4

I have a method that draws animated image on glass pane to simulate pulsing of an icon. It needs an image (i use icons of components) and bounds (of a button f.e.). I need this area:

enter image description here

I know that button has getBounds(), does tabs have something similar? Or maybe coordinates of an Icon. Either would be nice.

bunnyjesse112
  • 747
  • 6
  • 27
  • 44

4 Answers4

5

I had a similar problem. I needed height of tab. int tabHeight = myTabPanel.getUI().getTabBounds(myTabPanel, 0).height;.

Krzysztof Szewczyk
  • 1,752
  • 1
  • 21
  • 25
2

You have to create own BasicTabbedPaneUI, because these methods are protected and there no way to override these methods from outside, (that came from Standard Java API)

mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • thanks for answer. Could you provide small example? Or what are the names of methods i need to override in my BasicTabbedPaneUI? – bunnyjesse112 Dec 28 '11 at 11:30
  • you mean this? http://www.java2s.com/Code/Java/Swing-Components/ColorTabbedPaneExample.htm – bunnyjesse112 Dec 28 '11 at 12:11
  • 1) hmmm changed to http://www.google.com/cse?cx=partner-pub-1130008796007602%3Airi8be-v211&ie=ISO-8859-1&q=petersoft&sa=Search&siteurl=www.java2s.com%2F#gsc.tab=0&gsc.q=petersoft&gsc.page=1, sorry implemeted squid doesn't allows me opening this links, 2) maybe better workaround is by aephyr http://aephyr.googlecode.com/svn/trunk/ – mKorbel Dec 28 '11 at 12:25
  • I don't understand. Whats aephyr? Where's workaround? I'm mentally handicapped, please, explain in details! – bunnyjesse112 Dec 28 '11 at 12:48
  • You can create your own UI class, but that is not necessary. The answer two years later by Krzysztof should be brought to the top. Apologies; down-voted merely to get the other answer's score higher. – Loduwijk May 10 '17 at 21:55
2

@mKorbel is right about the UI delegate, but the effort is formidable. Alternatively, you may be able to leverage an animated icon, shown here, or a custom tab component, referenced here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
1

I know that button has getBounds(), does tabs have something similar?

See the getTabBounds() method of BasicTabbedPaneUI. You don't need to customize the class just to get this data. You only need to custom the UI if you intend to do the animation witin the UI.

The problem is that the size of the tab will just be the size of the text. So you won't have empty space for your icon unless you add an empty icon to the tab as well. If you are going to do this then you could use the Animatied Icon class which allows you to combine icons to perform animation.

camickr
  • 321,443
  • 19
  • 166
  • 288