• 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
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

JLabel Height  RSS feed

 
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: 60785
190
  • 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: 21502
96
Chrome Eclipse IDE Java Spring Ubuntu VI Editor 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: 2958
20
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!