Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tabs are collapsed

I am creating a GUI where the main window will contain a number of tabs. They should be positioned next to each other horizontally.

Using this code makes a "collapsed" version, where I can toggle the tabs with the arrows.

    JTabbedPane tabs = new JTabbedPane();
    JPanel tab_virksomheder = new JPanel();
    tabs.addTab("Virksomheder", tab_virksomheder);

    JPanel tab_praktikpladser = new JPanel();
    tabs.addTab("Praktikpladser", tab_praktikpladser);

    panel.add(tabs);

How can I make the tabs stand next to each other?

enter image description here

like image 523
Patrick Reck Avatar asked Dec 06 '25 08:12

Patrick Reck


2 Answers

The panel container should have a layout set like BorderLayout for instance.

panel.setLayout(new BorderLayout());
like image 52
Dan D. Avatar answered Dec 07 '25 22:12

Dan D.


The exact result depends on several things:

  • The platform's TabbedPaneUI, AquaTabbedPaneUI on Mac OS X.

  • The setting supplied to setTabLayoutPolicy().

  • The preferred size of the content, used when pack() is invoked on the enclosing Window.

You can use this example to experiment with various Look&Feel settings. Note how the content's preferred size defines the size of each tab's content pane.

image

like image 27
trashgod Avatar answered Dec 07 '25 20:12

trashgod