jdk/test/javax/swing/JTextArea/Test6593649.java
changeset 5592 fc99326b0953
parent 3504 3e34353145c5
child 5597 ab490f66d2cf
equal deleted inserted replaced
5591:a83d169f5153 5592:fc99326b0953
    28    @run main Test6593649
    28    @run main Test6593649
    29 */
    29 */
    30 
    30 
    31 import javax.swing.*;
    31 import javax.swing.*;
    32 import java.awt.*;
    32 import java.awt.*;
       
    33 import java.awt.event.ActionEvent;
       
    34 import java.awt.event.ActionListener;
    33 
    35 
    34 public class Test6593649 extends JFrame {
    36 public class Test6593649 {
    35   static JTextArea txt;
    37     private static JFrame frame;
    36   static JPanel innerPanel;
       
    37 
    38 
    38   public Test6593649(Dimension d)
    39     private static JTextArea textArea;
    39   {
       
    40     super("Word Wrap Testcase");
       
    41 
    40 
    42     setSize(d);
    41     private static final Timer timer = new Timer(1000, new ActionListener() {
       
    42         public void actionPerformed(ActionEvent e) {
       
    43             boolean failed = !textArea.getParent().getSize().equals(textArea.getSize());
    43 
    44 
    44     final Container contentPane = getContentPane();
    45             frame.dispose();
    45 
    46 
    46     innerPanel = new JPanel();
    47             if (failed) {
    47     innerPanel.setLayout(new BoxLayout(innerPanel, BoxLayout.LINE_AXIS));
    48                 throw new RuntimeException("The test failed");
       
    49             }
       
    50         }
       
    51     });
    48 
    52 
    49     txt = new JTextArea("This is a long line that should wrap, but doesn't...");
    53     public static void main(String[] args) throws Exception {
    50     txt.setLineWrap(true);
    54         SwingUtilities.invokeAndWait(new Runnable() {
    51     txt.setWrapStyleWord(true);
    55             public void run() {
       
    56                 frame = new JFrame();
    52 
    57 
    53     innerPanel.add(txt);
    58                 frame.setSize(200, 100);
    54 
    59 
    55     contentPane.add(innerPanel, BorderLayout.SOUTH);
    60                 textArea = new JTextArea("This is a long line that should wrap, but doesn't...");
    56   }
       
    57 
    61 
    58   public static void main(String[] args) throws InterruptedException
    62                 textArea.setLineWrap(true);
    59   {
    63                 textArea.setWrapStyleWord(true);
    60     int size = 100;
       
    61     Dimension d;
       
    62     Test6593649 cp;
       
    63     Dimension txtSize;
       
    64     Dimension innerSize;
       
    65     Dimension cpSize;
       
    66 
    64 
    67     while (size <= 600)
    65                 JPanel innerPanel = new JPanel();
    68     {
       
    69       d = new Dimension(size, size);
       
    70       cp = new Test6593649(d);
       
    71       cp.setVisible(true);
       
    72 
    66 
    73       txtSize = txt.getPreferredSize();
    67                 innerPanel.setLayout(new BoxLayout(innerPanel, BoxLayout.LINE_AXIS));
    74       innerSize = innerPanel.getPreferredSize();
    68                 innerPanel.add(textArea);
    75       cpSize = cp.getSize();
       
    76 
    69 
    77       if (!(txtSize.getWidth() == innerPanel.getWidth() && txtSize.getHeight() == innerPanel.getHeight() &&
    70                 frame.getContentPane().add(innerPanel, BorderLayout.SOUTH);
    78            txtSize.getWidth() <= cpSize.getWidth() && txtSize.getHeight() <= cpSize.getHeight()))
       
    79       {
       
    80         throw new RuntimeException("Test failed: Text area size does not properly match panel and frame sizes");
       
    81       }
       
    82 
    71 
    83       Thread.sleep(2000);
    72                 frame.setVisible(true);
    84 
    73 
    85       cp.hide();
    74                 timer.setRepeats(false);
    86       size += 50;
    75                 timer.start();
       
    76             }
       
    77         });
    87     }
    78     }
    88   }
       
    89 }
    79 }