Greetings- Plain and simple, is it possible to hide the tabs in a JTabbedPane (and if so, how)? Tabs are unnecessary as the users can select what panel they want to view via a JTree on the side. I am aware that there is a CardLayout that would suite my needs, but I would like to keep the JTabbedPane in place so that the tab visibility can be changed depending on user preference.
you can do something like this, which just doesn't paint the tabArea
problems are: 1) needs additional code to paint the top tab border, where it joins tabArea 2) can still click the 'invisible' tab area, to change tabs 3) even though tabAreas are not shown, the space allocated remains, i.e. the pane of the JTabbedPane is lower in its container than a cardlayout would be
seems it might be a lot easier to switch between cardLayout/JTabbedPane, as required
Joined: Dec 27, 2005
Thanks to both of you for your input. I have decided to implement both the JTabbedPane and the CardLayout, and let the user select which he or she would like to use.
Can only agree with Michael ... moving the tabs out of the visible area is definitely not a good solution.
Maybe have a look at how JTabbedPane handles the tabs internally and do something similar. What might possibly work is to keep all the tabs (JPanels?) in an arry and set the content of the displaying container (where the JTabbedPae used to be) as users click in the JTree? Or just move the JTabbedPane's tab location to the left and omit the JTree, it it's only a question of layout ...
Thanks for the information. We've sub classed JTabbedPane and my version(FlexJTabbedPane) has a getTabAt() LOL.... I'll be more careful next time. We likely added getTabAt() prior to Java 6 being released. I will remove it from my class now that you have enlightened me. Thanks.
solution to issue 2("can still click the 'invisible' tab area, to change tabs") is overriding of BasicTabbedPaneUI.tabForCoordinate.
I place my own version of JTabbedPane_withoutPaintedTabs for these people who are in search yet
There are no new questions, but there may be new answers.
Joined: Sep 12, 2013
to Darryl Burke and Campbell Ritchie: you are correct , of course. But please read intently question from topic starter: "I am aware that there is a CardLayout that would suite my needs, but I would like to keep the JTabbedPane in place so that the tab visibility can be changed depending on user preference". I had the same requirements.