I am at my wit's end trying to figure out how to avoid the exception thrown below when in this case removing 1 tab in tabbedpane at index 0.
Here is my code. Code gets action map on JTabbedPane.
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
at com.program.program.ArchiveTabPane$4.stateChanged(Unknown Source)
at com.program.program.ArchiveTabPane$2$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
if I modify the code to this below I can get a print out of 1 item before I click on the little X button to close the tab. I am doing the testing with just 1 tab in tabbed pane. I add minus 1 to get index 0 as you see in my first post. If I have no code after actionPerformed, the tab does not close upon clicking the little button with X on top. If I test the code with more than one tab, I can close all the tabs except the last one at index 0. Index 0 always throw the exception. I tried removeAll() with 1 tab and at index 0 of course and that throws an exception too.
Your ArchiveTabPanel also listens on changes on the tab panel. When you remove the tab, a ChangeEvent is fired and the stateChanged() method on your ArchiveTabPanel is executed (although it seems to be in a different package?). This method has a logical error: It tries to get the title of tab with index -1.
Thank you Paul Balm. You were right. The problem was the wrong choice of method in changeListener (on 3rd line). It's important to thoroughly follow up on stack traces. Thanks Paul once again for bringing this to my attention.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com