• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

Deleting Row from JTable

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I just started working in JAVA. I am creating a simple GUI, in which, jTable displays the messages (id, text, etc...)

I am getting exception while removing rows from JTable.

I am using JTable to display the messages, which come very fast. (At once I can get 100 messages same time).

Basically when any message comes with type = ADD_MESSAGE, i add a row in jTable.
When any message comes with type = DELETE_MESSAGE, I remove the row from the jTable.

First I put all these messages into a queue and a separate thread handling this message_queue.


Here is the some part of my code:

message_queue # queue of messages...

For each message ... Thread calls a function call Handle_Message(message)

-----------------------------------------------------------------------------------------------------------------

It removes the row correctly without any error. But it throws an exception while painting a jTable, I guess,

Here is the output:

-----------------------------------------------------------------------------------------------------

Message: PUBLISH|ID=1022|NAME=message1|TYPE=ADD_MESSAGE|MESSAGE_ID=#698|
Row Added...
Message: PUBLISH|ID=1023|NAME=message2|TYPE=ADD_MESSAGE|MESSAGE_ID=#699|
Row Added...
Message: PUBLISH|ID=1024|NAME=message3|TYPE=ADD_MESSAGE|MESSAGE_ID=#700|
Row Added...
Message: PUBLISH|ID=1025|NAME=message4|TYPE=ADD_MESSAGE|MESSAGE_ID=#701|
Row Added...
Message: PUBLISH|ID=1026|NAME=message5|TYPE=ADD_MESSAGE|MESSAGE_ID=#702|
Row Added...
Message: PUBLISH|ID=1027|NAME=message6|TYPE=ADD_MESSAGE|MESSAGE_ID=#703|
Row Added...
Message: PUBLISH|ID=1028|NAME=message7|TYPE=ADD_MESSAGE|MESSAGE_ID=#704|
Row Added...
Message: PUBLISH|ID=1029|NAME=message8|TYPE=ADD_MESSAGE|MESSAGE_ID=#705|
Row Added...
Message: PUBLISH|ID=1030|NAME=message9|TYPE=ADD_MESSAGE|MESSAGE_ID=#706|
Row Added...
Message: PUBLISH|ID=1031|NAME=message10|TYPE=ADD_MESSAGE|MESSAGE_ID=#707|
Row Added...

Message: PUBLISH|ID=1032|NAME=message1|TYPE=DELETE_MESSAGE|MESSAGE_ID=#698|
Row Deleted...
Message: PUBLISH|ID=1033|NAME=message2|TYPE=DELETE_MESSAGE|MESSAGE_ID=#699|
Row Deleted...
Message: PUBLISH|ID=1034|NAME=message3|TYPE=DELETE_MESSAGE|MESSAGE_ID=#700|
Row Deleted...
Error in application
Java::JavaLang::ArrayIndexOutOfBoundsException - java.lang.ArrayIndexOutOfBoundsException: 7 >= 7
java.lang.ArrayIndexOutOfBoundsException: 7 >= 7
at java.util.Vector.elementAt(Vector.java:432)
at javax.swing.table.DefaultTableModel.getValueAt(DefaultTableModel.java:621)
at javax.swing.JTable.getValueAt(JTable.java:1903)
at javax.swing.JTable.prepareRenderer(JTable.java:3911)
at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:2072)
at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:1974)
at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:1897)
at javax.swing.plaf.ComponentUI.update(ComponentUI.java:154)
at javax.swing.JComponent.paintComponent(JComponent.java:743)
at javax.swing.JComponent.paint(JComponent.java:1006)
at javax.swing.JComponent.paintChildren(JComponent.java:843)
at javax.swing.JComponent.paint(JComponent.java:1015)
at javax.swing.JViewport.paint(JViewport.java:728)
at javax.swing.JComponent.paintChildren(JComponent.java:843)
at javax.swing.JComponent.paint(JComponent.java:1015)
at javax.swing.JComponent._paintImmediately(JComponent.java:4890)
at javax.swing.JComponent.paintImmediately(JComponent.java:4676)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:477)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:114)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

Message: PUBLISH|ID=1035|NAME=message4|TYPE=DELETE_MESSAGE|MESSAGE_ID=#701|
Row Deleted...
Message: PUBLISH|ID=1036|NAME=message5|TYPE=DELETE_MESSAGE|MESSAGE_ID=#702|
Row Deleted...
Message: PUBLISH|ID=1037|NAME=message6|TYPE=DELETE_MESSAGE|MESSAGE_ID=#703|
Row Deleted...
Message: PUBLISH|ID=1038|NAME=message7|TYPE=DELETE_MESSAGE|MESSAGE_ID=#704|
Row Deleted...
Message: PUBLISH|ID=1039|NAME=message8|TYPE=DELETE_MESSAGE|MESSAGE_ID=#705|
Row Deleted...
Message: PUBLISH|ID=1040|NAME=message9|TYPE=DELETE_MESSAGE|MESSAGE_ID=#706|
Row Deleted...
Message: PUBLISH|ID=1041|NAME=message10|TYPE=DELETE_MESSAGE|MESSAGE_ID=#707|
Row Deleted...

----------------------------------------------------------------------------------------------------------------

But if I put wait (or sleep) for one sec, I don't see any exception. But that delays an app, if there are
more messages coming.

Please let me know if anyone know how to fix this.

In order to do that I created MyTableModel(extending DefaultTableModel) so that I can catch the exception
in ValueAt() method.

But some how it's not calling getValueAt( ) method from MyTableModel,but it is calling from DefaultTableModel.

Please let me know.

Thanks

Nas

 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you getting the error only when you try to delete the first or last table row? If so you need to cater this in your Remove_Row method. Do check your for loop < vs <=
 
Nasir Baig
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reply,

As I said I don't get any error in remove code. It removes the row correctly. Here is the loop:



I get an exception when one of java thread try to repaint the table after removing row.

----------------------------------------------------------------------------------------------------------------
Message: PUBLISH|ID=1032|NAME=message1|TYPE=DELETE_MESSAGE|MESSAGE_ID=#698|
Row Deleted...
Message: PUBLISH|ID=1033|NAME=message2|TYPE=DELETE_MESSAGE|MESSAGE_ID=#699|
Row Deleted...
Message: PUBLISH|ID=1034|NAME=message3|TYPE=DELETE_MESSAGE|MESSAGE_ID=#700|
Row Deleted...
Java::JavaLang::ArrayIndexOutOfBoundsException - java.lang.ArrayIndexOutOfBoundsException: 7 >= 7
java.lang.ArrayIndexOutOfBoundsException: 7 >= 7
at java.util.Vector.elementAt(Vector.java:432)
at javax.swing.table.DefaultTableModel.getValueAt(DefaultTableModel.java:621)

at javax.swing.JTable.getValueAt(JTable.java:1903)
at javax.swing.JTable.prepareRenderer(JTable.java:3911)
at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:2072)
at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:1974)
at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:1897)
at javax.swing.plaf.ComponentUI.update(ComponentUI.java:154)
at javax.swing.JComponent.paintComponent(JComponent.java:743)
at javax.swing.JComponent.paint(JComponent.java:1006)
at javax.swing.JComponent.paintChildren(JComponent.java:843)
at javax.swing.JComponent.paint(JComponent.java:1015)
at javax.swing.JViewport.paint(JViewport.java:728)
at javax.swing.JComponent.paintChildren(JComponent.java:843)
at javax.swing.JComponent.paint(JComponent.java:1015)
at javax.swing.JComponent._paintImmediately(JComponent.java:4890)
at javax.swing.JComponent.paintImmediately(JComponent.java:4676)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:477)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:114)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Message: PUBLISH|ID=1035|NAME=message4|TYPE=DELETE_MESSAGE|MESSAGE_ID=#701|
Row Deleted...
Message: PUBLISH|ID=1036|NAME=message5|TYPE=DELETE_MESSAGE|MESSAGE_ID=#702|
Row Deleted...
Message: PUBLISH|ID=1037|NAME=message6|TYPE=DELETE_MESSAGE|MESSAGE_ID=#703|
Row Deleted...
Message: PUBLISH|ID=1038|NAME=message7|TYPE=DELETE_MESSAGE|MESSAGE_ID=#704|
Row Deleted...
Message: PUBLISH|ID=1039|NAME=message8|TYPE=DELETE_MESSAGE|MESSAGE_ID=#705|
Row Deleted...
Message: PUBLISH|ID=1040|NAME=message9|TYPE=DELETE_MESSAGE|MESSAGE_ID=#706|
Row Deleted...
Message: PUBLISH|ID=1041|NAME=message10|TYPE=DELETE_MESSAGE|MESSAGE_ID=#707|
Row Deleted...
---------------------------------------------------------------------------------------------------------------

Please let me know.

Thanks

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic