-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);
mKorbel
  • 109,525
  • 20
  • 134
  • 319
haind
  • 1,000
  • 2
  • 16
  • 28
  • 1
    `I create a jTabPanl` - I assume you mean JTabbedPane. Use proper class names so we don't have to guess what you are talking about. – camickr Oct 06 '13 at 03:35
  • I think that when I ask a question I should make it simple as possible. This is demo. Anyway, thank for your opinion – haind Oct 06 '13 at 03:48
  • *"thank for your opinion"* That 'opinion', or as I would describe it 'excellent advice', is not just thought by the person that said it. But I'll go further. If you could not be bothered typing the name correctly or copy/pasting it, please stop wasting our time. – Andrew Thompson Oct 06 '13 at 03:54
  • @Andrew Thompson. Please don't take it a wrong way. All I did is find for a help. I don't know too much. And I really don't know my question is a little bit difficult to guess. At first, I think it must be more complex also. – haind Oct 06 '13 at 04:30

1 Answers1

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.

camickr
  • 321,443
  • 19
  • 166
  • 288