This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 38045
    
  22
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
 
Similar Threads
jtable: column header click
jtable
Jtable mouse header cursor
JTable Columns
JTable question