Java Swing How to - Change Tabs' position of JTabbedPane








Question

We would like to know how to change Tabs' position of JTabbedPane.

Answer

import java.awt.BorderLayout;
import java.awt.Dimension;
//from  w w  w .  j  a  va 2s .  c o  m
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.WindowConstants;

public class Main {

  public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.getContentPane().add(new TabView());
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.setMinimumSize(new Dimension(800, 450));
    frame.pack();
    frame.setVisible(true);
  }
}
class TabView extends JPanel {
  JTabbedPane tabbedPane = new JTabbedPane();
  TabView() {
    tabbedPane.addTab("Hello", new JLabel("World"));
    tabbedPane.addTab("Goodbye", new JLabel("Sunshine"));
    setLayout(new BorderLayout());

    tabbedPane.setTabPlacement(JTabbedPane.TOP);
    tabbedPane.setTabLayoutPolicy(JTabbedPane.WRAP_TAB_LAYOUT);
    add(tabbedPane, BorderLayout.CENTER);
  }
}