Exception thrown while working with JTabbedPane
- by Halo
I'm using a JTabbedPane in my application and I listen to its changes with ChangeListener so that I can know which tab is currently selected.
So my stateChanged method is;
public void stateChanged(ChangeEvent e) {
currentPageIndex = jTabbedPane.getSelectedIndex();
}
But while I'm adding new tabs to the JTabbedPane it throws an ArrayIndexOutOfBoundsException in the method above, I don't know why. Some suggested for a similar case that this is a bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4873983, but as you'll see some says the solution is to work with Swing from EventDispatchThread.
What does it mean, do they mean the SwingUtilities.invokeLater thing? Can someone show me how I can modify my stateChanged method accordingly to avoid the exception?