File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java Interview Guide this week in the Jobs Discussion 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

programatically size JFrame after data in JLabel changes

Jim Harrison
Ranch Hand

Joined: Mar 16, 2007
Posts: 30

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.

Rob Spoor

Joined: Oct 27, 2005
Posts: 20279

Call pack().

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..
I agree. Here's the link:
subject: programatically size JFrame after data in JLabel changes
It's not a secret anymore!