Java tutorial
import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTabbedPane; import javax.swing.SwingConstants; public class Main { public static void main(String[] args) { JTabbedPane tabbedPane = new JTabbedPane(); for (int i = 0; i < 5; i++) { tabbedPane.add("Tab " + i, new JLabel("Label " + i, SwingConstants.CENTER)); } tabbedPane.getModel().addChangeListener(e -> { JLabel label = (JLabel) tabbedPane.getSelectedComponent(); System.out.println(label.getText()); }); tabbedPane.setPreferredSize(new Dimension(500, 300)); JFrame frame = new JFrame(); frame.getContentPane().add(tabbedPane); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); } }