views:

1133

answers:

2

I want a behavior similar to e.g. Firefox where the list of available tabs does only show up if at least two tabs exist.

I wasn't able to find anything like that, yet.

The best idea I had was changing the layout manually:

  • in case of one component, just add that to the surrounding panel
  • if a component is added, remove the component from the surrounding panel, add a JTabbedPane instead and add both the previous and the new component to that pane.
  • if a component is removed and only one component is left in the pane, remove the pane and add the contained component instead.

While this would probably work it feels like a hack or workaround...

Any better idea?

A solution should ideally work in both Java 1.5 and 1.6... but I'd be happy about a 1.6-only solution, too.

+3  A: 

I believe you'll have to do it manually. Apparently it has been done before, but only as a small bit of a system which seems to not be available.

Your approach looks good to me. I would do it just like you laid it out, and wrap all that logic in a custom JComponent so it will feel less hackish.

Michael Myers
I'll wait a little longer to see if someone has a brilliant idea before checking the answer...
Huxi
I agree with @mmyers. If someone has a prebuilt component to do this I'd be pretty certain it worked this way.
banjollity
Thanks, I guess there's really no other way...
Huxi
Sorry. If anyone finds such a component or makes one, I would like to hear about it.
Michael Myers
+2  A: 

You may be better of by simply using CardLayout. Check it out at http://java.sun.com/javase/6/docs/api/java/awt/CardLayout.html

eugener
Good general idea but I want to have a JTabbedPane incl. the various looks regarding PLAF. Anyway, your input is appreciated.
Huxi
+1 for this is what I would have done
willcodejavaforfood