Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Resizing JTextArea

843804Dec 29 2004 — edited Dec 30 2004
Can someone give me some pointers on the best way to have a JTextArea automatically resize itself to fill the container when its container size changes?

I have an app that has three panels. The center panel has a JTextArea that I would like to shrink and grow based on the size of the JFrame holding the panels. Panel one is NORTH, panel two is CENTER and panel 3 is SOUTH. Panels one and three I want to keep the same vertical size while panel 2 shrinks and grows.

I've tried adding a ComponentListener to listen for comonentResize then setRows and setColumns on the JTextArea to no avail:( I've tried Using a GridBag Layout manager with GridBagConstraints fill = GridBagConstraints.BOTH, but that didn't do it for me either.

I'm thinking this is a fairly rudimentary task that I'm missing the obvious on, but those are always the hardest to find.

Does anyone have any example code that produces this functionality for a JTextArea?

Thanks
G
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 27 2005
Added on Dec 29 2004
2 comments
170 views