• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting JTextArea to resize within a JScrollPane

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Ranch Hand
Posts: 4632
  • Likes 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic