0

What I want is something similar to the tab-selection part of a JTabbedPane, but without the panel below it which automatically fills with content associated with the tabs.

This way, I can detect the selection of tabs using a listener and do something else based on it.

I don't think there are any other components which could achieve this, so the best solution will probably be some way of manipulating a JTabbedPane so that it only displays the tabs and hides the panes below it.

I would very much appreciate any ideas. Thanks in advance!

  • 1
    Why not a panel of buttons or a `JToolBar`? – trashgod Nov 08 '16 at 03:26
  • 1
    Why do you try to not show anything in the tabs? What is the purpose of your application? – hamena314 Nov 08 '16 at 08:38
  • @hamena314 I want to use the tabs as a control for an unrelated part of the application. – flipnaz17 Nov 08 '16 at 17:33
  • @trashgod I was hoping to maintain the look and feel of the tabs. – flipnaz17 Nov 08 '16 at 17:34
  • You can override `getPreferredSize()`](http://stackoverflow.com/q/7229226/230513) on the content. – trashgod Nov 08 '16 at 18:51
  • @trashgod Even if the content inside each tab returns a preferred and maximum size of (0,0), or if the content in each tab is `null`, the layout manager inside `TabbedPaneUI` is still giving some non-zero size to each tab component. If you then override `getPreferredSize()` on `JTabbedPane` itself, that will work, but you may have to simply guess at the correct height to leave for the drawing of the tabs, which is probably not a good idea. The real size depends on font size and other things. – Enwired Nov 08 '16 at 19:12
  • @trashgod @Enwired Yeah, so far my best solution has been to set the preferred size height of the `JTabbedPane` to `1.6 * pane.getFont().getSize()` which is not a very robust solution. Besides, even if we assume that this method of estimating the height is perfect, the `JTabbedPane` still renders an undesired horizontal line at the bottom of the component, no matter how small I set the preferred size. – flipnaz17 Nov 08 '16 at 21:58

0 Answers0