• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JLabel Height

 
Ranch Hand
Posts: 838
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 838
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 838
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Goodbye moon men. Hello tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic