-1

I create a jTabPanl with 3 tab: add, update, remove for example. It can be if I click on each tab, it show index tab such as:

  • click on Add tab, it do System.out.println("clicking tab 0")
  • click on Update tab, it do System.out.println("clicking tab 1")
  • click on Delete tab, it do System.out.println("clicking tab 3") Can anyone help me?

Finally, I do it:

ChangeListener changeListener = new ChangeListener() {

    @Override
    public void stateChanged(ChangeEvent e) {
        jTabbedPane1 = (JTabbedPane) e.getSource();
        int index = jTabbedPane1.getSelectedIndex();
            System.out.println("click tab " + index);
    }
};

jTabbedPane1.addChangeListener(changeListener);
4

1 回答 1

2

Add a ChangeListener to the JTabbedPane. When the listener fires you will need to get the currently selected tab from the JTabbedPane and then do your processing.

Read the Swing tutorial on How to Write a Change Listener for basic information on change listeners.

于 2013-10-06T03:32:11.857 回答