Exception thrown while working with JTabbedPane

Posted by Halo on Stack Overflow See other posts from Stack Overflow or by Halo
Published on 2010-05-01T20:53:48Z Indexed on 2010/05/01 20:57 UTC
Read the original article Hit count: 373

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about java

Related posts about jtabbedpane