This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting JTextArea to resize within a JScrollPane

 
Ian Taylor
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there

I am currently writing an app that contains a JTextArea to output information. It is contained within a JScrollPane, the idea being that once there becomes too much data to display on the text area, the text area automatically grows to fit the available data and the scroll pane kicks in to scroll up and down (horizontal is not an issue as I'm using text wrapping).

Unfortunately I can't seem to find the right combination of preferred size and maximum size on either component to get my app to do this. If I set my preferred size to the starting area and the maximum size to something arbitrarily large, then the text area never grows. Once the data gets to the bottom of the visible area it just stops displaying. I can 'fix' the problem by setting the preferred size to something arbitrarily large, then the text area scrolls as required within the scroll pane, but unfortunately the scroll bars are always there and the area is always scrollable regardless of whether there is any data there to fill it. This makes the app technically functional but ultimately ugly. I am using Gridbag layout, I'm not sure if that's relevant.


 
Michael Dunn
Ranch Hand
Posts: 4632
  • 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
looks like you've over-complicated everything.

provided you have the right layout manager for the scrollpane,
this is all you need to do
 
Ian Taylor
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Dunn wrote:looks like you've over-complicated everything.

provided you have the right layout manager for the scrollpane,
this is all you need to do


To be honest, I created the jFrame with Netbeans which added that code for me. Obviously the size variable changes are a result of me messing around trying to get the thing to work.
 
Ian Taylor
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fixed.

You're totally right I was overcomplicating it. Removed all the size parameters then it worked just fine.

If a mod wants to move this to the noob forum I totally understand
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic