• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Removing column from JTable

 
Ranch Hand
Posts: 191
Netbeans IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 191
Netbeans IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.





 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic