2 Replies Latest reply: Feb 14, 2013 1:36 AM by 978140 RSS

    Resizing a JTextArea

    978140
      Hi. Cant find out why my textarea messes up the JFrame size. Can anyone help?
      import javax.swing.JFrame;
      import javax.swing.JPanel;
      import javax.swing.JTextArea;
      
      
      public class TestTextArea {
      
           public static void main(String[] args){
                JFrame frame = new JFrame("test");
                
                // CREATE TEXT AREA
                JTextArea desc = new JTextArea(4,25);
                desc.setLineWrap(true);
                desc.setWrapStyleWord(true);
                
                // ADD TEXT TO TEXTAREA
                desc.setText("A lot of text here that automaticaly will go down lines but of some reason changes the frame size when rezising window");
                
                // ADD TEXTAREA O A PANEL
                JPanel panel = new JPanel();
                panel.add(desc);
                
                // ADD THE PANEL TO THE FRAME
                frame.add(panel);
                frame.setVisible(true);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.pack();
           }
      }
      When I resize the JFrame with the mouse the JFrame gets huge. Any tips on how to make the JFrame behave more as expected?