This discussion is archived
2 Replies Latest reply: Feb 13, 2013 11:36 PM by 978140 RSS

Resizing a JTextArea

978140 Newbie
Currently Being Moderated
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?

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points