aspose file tools*
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
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JLabel Height" Watch "JLabel Height" New topic
Author

JLabel Height

Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 828
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
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
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: 828
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
Sheriff

Joined: Oct 27, 2005
Posts: 19785
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 828
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: 2227
    
    8
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