I need to detect when the selected tab changes, and get its index.
The following code works, but it fires the println
as many times as the amount of tabs currently loaded:
tabbedPane.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
System.out.println("Tab: " + tabbedPane.getSelectedIndex());
// Prints the string 3 times if there are 3 tabs etc
}
});
What is the correct way of doing this?
stateChanged
so yes. I could use a counter so only the last event calls the mentioned DB method but maybe there's a clearer way? – Radarman