3

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

Patrick Reck
  • 303
  • 1
  • 10
  • 24
  • Read the JTabbedPane API and follow the link to the Swing tutorial on "How to Use Tabbed Panes" for a working example. – camickr Feb 14 '13 at 16:34

2 Answers2

2

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

panel.setLayout(new BorderLayout());
Dan D.
  • 32,246
  • 5
  • 63
  • 79
1

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

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045