wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes JLabel Height Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JLabel Height" Watch "JLabel Height" New topic

JLabel Height

Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 815
Is there a way to determine the height of a JLabel? I want to know what the leftover height is of a JPanel after a JLabel has been added. Thanks.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 37926
This method any good? I think I ought to move this thread to our GUIs forum.
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 815
No, I need to find the height of JLabel before or just after I add it to the JPanel. I need to know how much of the JPanel's height I have left to work with for other components.
Rob Spoor

Joined: Oct 27, 2005
Posts: 19649

That's the work of layout managers. You shouldn't worry about that unless you're writing your own layout manager, in which case getPreferredSize().getHeight() is the method to use.

How To Ask Questions How To Answer Questions
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 815
I'm trying to draw a circle on a JPanel that will be added and I need to draw it based on a certain percentage. If I pass a "parent" value of 100 (which is largest number of a circle) and a child value of 50 then circle needs to be 1/2 the size (in area) of the parent. The way I was going to do it was to determine the area I was dealing with (I'll be adding labels and such below this panel within the JFrame). I need to have the circle display proportional to a value passed in. Any ideas on how to accomplish this otherwise? I'm open to ideas. Thanks for the posts.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2152
Add you label to the NORTH of a BorderLayout and the custom panel to the CENTER. All the extra space will go to the CENTER. The size of the component is known in the paintComponent() method. Since you should be drawing the circle in the paintComponent() method there shold be no problem to do what you want.

Post your SSCCE demonstrating the problem.
I agree. Here's the link: http://aspose.com/file-tools
subject: JLabel Height
Similar Threads
WA #1.....word association
Resize width only?
best layout to use
JPanel.validate() repositions DnD Components
Changing Fonts