dynamically set JTextArea dimensions

Any pointers or examples in setting a JTextArea to the same width as a JPanel, but specifing a height?

And if the JFrame that contains the JPanel is extended (dragged bigger|smaller), resize the JTextArea to fit.
LVL 16
ellandrdAsked:
Who is Participating?
 
objectsCommented:
try something like:

JPanel panel = new JPanel(new BorderLayout());
JTextArea ta = new JTextArea();
JScrollPane sp = new JScrollPane(ta);
sp.setPreferredSize(new Dimension(Integer.MAX_VALUE, desiredHeight));
sp.setMaximumSize(new Dimension(Integer.MAX_VALUE, desiredHeight));
panel.add(BorderLayout.NORTH, sp);

you can get rid of the scroll pane if you don't want one. in which case set the preferred size of the ta
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.