aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Removing column from JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Removing column from JTable" Watch "Removing column from JTable" New topic
Author

Removing column from JTable

Isaac Hewitt
Ranch Hand

Joined: Jul 24, 2006
Posts: 190



I want a user to be able to remove a column by tripleclicking on the tableheader. My code below works properly except it throws an Exception the second time the header is clicked. The column is still removed nonetheless, but I would like to avoid the Exception:

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 3 >= 3
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39784
    
  28
Please give more details. It is usually quite easy to work out what ArrayIndexOutOfBoundsException means, but there doesn't seem to be an array in the code snippet you posted.

Please check whether any of the methods you are calling might throw such an Exception (but it would be unusual for it to be declared in a "throws").

Remember that in GUI work you have several threads running simultaneously, and an Exception might stop the thread it occurs in without the whole app terminating. Also, that the fact that your Listener (which is what you have quoted looks like) sets off the Exception doesn't necessarily prove that the Exception occurs there. You can usually find out by looking at the class and line number given on the first line of the stack trace.

CR
Isaac Hewitt
Ranch Hand

Joined: Jul 24, 2006
Posts: 190

I am very sorry for wasting your time Mr. Ritchie. I spent some time examining my class and after making a change, the Exception went away.

The FOR loop further below in the second code snippet seems to have solved the problem.

Before adding the FOR loop, I had used the following snippet which was intended to equalize the width of all 4 columns after a doubleclick on the tableheader. The new FOR loop does the same thing.

Hopefully someone else learning Java can learn from this mistake. Thanks for responding.





 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Removing column from JTable