get current tab index java swing

Solutions on MaxInterview for get current tab index java swing by the best coders in the world

showing results for - "get current tab index java swing"
Tommaso
25 Jan 2020
1 public static void main(String[] args) {
2  JFrame frame = new JFrame();
3  frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
4  frame.setBounds(0, 0, 300, 400);
5  frame.setLayout(null);
6  final JTabbedPane tabbedPane = new JTabbedPane();
7  tabbedPane.addTab("One", new JPanel());
8  tabbedPane.addTab("Two", new JPanel());
9  tabbedPane.addTab("Three", new JPanel());
10  tabbedPane.addChangeListener(new ChangeListener() {
11    public void stateChanged(ChangeEvent e) {
12      System.out.println("Tab: " + tabbedPane.getSelectedIndex());
13    }
14  });
15  tabbedPane.setBounds(0, 0, 300, 400);
16  frame.add(tabbedPane);
17  frame.setVisible(true);
18}
19