This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes programatically size JFrame after data in JLabel changes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "programatically size JFrame after data in JLabel changes" Watch "programatically size JFrame after data in JLabel changes" New topic
Author

programatically size JFrame after data in JLabel changes

Jim Harrison
Greenhorn

Joined: Mar 16, 2007
Posts: 29
Hello...

I have a JFrame whose contents consist of alot of JLabels that can either be text or images or both. The user can also change the font for these (all fonts will be the same size). My problem is how do I resize to ensure the JFrame to ensure all the contents are visible? All the contents are data driven. I'm using JDK 6_13 on Windows machine.

Thanks.Jim
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Call pack().


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Shrinath M Aithal
Ranch Hand

Joined: May 20, 2009
Posts: 82
thanks Rob
I was about to post new thread while I got this..
I am trying a quiz application with swings, so while showing the question,
I wanted to display the question through a Label. (I specifically wanted Label because I am using JDesktopPane with Nimbus background and I like to show it off.. so if i use textarea or textpane, it'll show as white and wouldn't be as good as label..)
So while trying to fit the question inside label, I learn't how to use multiline using html tags..


Problem is that whenever the label would go out of screen size, I couldn't get the desktoppane to scroll to that area, even if the desktop pane was inside a scrollpane.

after i saw your post here, i used pack() after resizing the desktop pane, and it Worked!!.. thanks a lot, and any comments on what i am trying to achieve is welcome..
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: programatically size JFrame after data in JLabel changes
 
Similar Threads
When will BufferedReader.ready() status will be true
Which access modifier should you use for constants?
Regarding JFrame maximise and minimise
Control the minimum size of a JFrame
Merged files? (can't think of a better name)