Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

JLabel Height

 
Ranch Hand
Posts: 837
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 69863
278
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This method any good? I think I ought to move this thread to our GUIs forum.
 
Rob Hunter
Ranch Hand
Posts: 837
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Hunter
Ranch Hand
Posts: 837
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 3191
29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
These are the worst of times and these are the best of times. And this is the best tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic