1 /*
   2  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @key headful
  27  * @bug 6593649
  28  * @summary Word wrap does not work in JTextArea: long lines are not wrapped
  29  * @author Lillian Angel
  30  * @run main Test6593649
  31  */
  32 
  33 import javax.swing.*;
  34 import java.awt.*;
  35 import java.awt.event.ActionEvent;
  36 import java.awt.event.ActionListener;
  37 
  38 public class Test6593649 {
  39     private static JFrame frame;
  40 
  41     private static JTextArea textArea;
  42 
  43     private static final Timer timer = new Timer(1000, new ActionListener() {
  44         public void actionPerformed(ActionEvent e) {
  45             boolean failed = !textArea.getParent().getSize().equals(textArea.getSize());
  46 
  47             frame.dispose();
  48 
  49             if (failed) {
  50                 throw new RuntimeException("The test failed");
  51             }
  52         }
  53     });
  54 
  55     public static void main(String[] args) throws Exception {
  56         SwingUtilities.invokeAndWait(new Runnable() {
  57             public void run() {
  58                 frame = new JFrame();
  59 
  60                 frame.setSize(200, 100);
  61 
  62                 textArea = new JTextArea("This is a long line that should wrap, but doesn't...");
  63 
  64                 textArea.setLineWrap(true);
  65                 textArea.setWrapStyleWord(true);
  66 
  67                 JPanel innerPanel = new JPanel();
  68 
  69                 innerPanel.setLayout(new BoxLayout(innerPanel, BoxLayout.LINE_AXIS));
  70                 innerPanel.add(textArea);
  71 
  72                 frame.getContentPane().add(innerPanel, BorderLayout.SOUTH);
  73 
  74                 frame.setVisible(true);
  75 
  76                 timer.setRepeats(false);
  77                 timer.start();
  78             }
  79         });
  80     }
  81 }