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
Sean O'Donnell
Greenhorn
Joined: Dec 27, 2005
Posts: 12
posted
0
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.
Joel Bronte
Greenhorn
Joined: Aug 04, 2008
Posts: 1
posted
0
Just in case someone else reads this post.
An easy way to do this is to use absolute layout and put the JTabbedPane inside a JPanel at location (0,-tabHeight) or simply:
jPanel.setLayout(null); jPanel.add(jTabbedPanel); jTabbedPane.setLocation(0,-25); jTabbedPane.setSize(sizeX,sizeY); //need setSize also since using null layout
NOTE: if window resizing is an issue you'll need to overwrite setSize on jPanel to change the size of jTabbedPane also when the user resizes.
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
> An easy way to do this is to use absolute layout....
and then the nightmare begins.
Guido Sautter
Ranch Hand
Joined: Dec 22, 2004
Posts: 142
posted
0
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 ...
If you have noticed, the original post is from 2007! I doubt if the original poster is waiting for the solution that long! http://faq.javaranch.com/java/DontWakeTheZombies Also the actual method is JTabbedPane#getTabComponentAt(int index).
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.
Dmitry Gundorov
Greenhorn
Joined: Jan 18, 2010
Posts: 1
posted
0
I've had the same problem and sorted it this way:
You can also get rid of the gray border around the tabbed pane by overriding method paintContentBorder(Graphics g, int tabPlacement, int selectedIndex).
Rob Clawson
Greenhorn
Joined: May 19, 2010
Posts: 2
posted
0
Overriding the calculateTabAreaHeight method was perfect. Just what I needed. To make the display work properly though, I also had to override the paintTab method.