• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Getting the size of a tab in a JTabbedPane

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are no member functions in the JTabbedPane class to retrieve the size of a tab from a JTabbedPane. There are only member functions to return the # of tabs and the # of rows or columns the tabs are using. Is there a trick to get the size of each tab in the JTabbedPane?
For example, suppose there are 2 tabs in the JTabbedPane. The first tab contains the text "Tab" and the second tab contains the text "This is a Big Tab". Obviously the sizes of the tabs are going to be different, but currently there is no way to obtain their sizes based upon the member functions of the JTabbedPane class. Is there a workaround to this?
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

From my point of view you can only calculate it, from the size of the title string plus a constant number, for the margins.
The size of the string can be calculated in pixels using the
FontMetrics class, and of course it is dependent on the string and on the font that is used.
Ana
 
Greenhorn
Posts: 5
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In case anyone else (like I was) is still searching for the answer to this question in 2016. :-)

Size of the Tab is now specifically available via JTabbedPane.getBoundsAt(<which_tab>).

Returns the rectangle (x,y,width,height) containing the Tab.

Remember Tabs number internally from 0 to <number-of-tabs> - 1.

Cheers,
Warren K.
 
And tomorrow is the circus! We can go to the circus! I love the circus! We can take this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic