Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem in JTable  RSS feed

 
Amaresh P
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
I am showing a list of records (each record in a row) in a JTable
(DefaultTableModel).
The requirement is that a maximum of 1100 rows to be displayed
in the list. When the number of rows exceeds this limit, I am bringing
the count to 1000 by deleting the initial records.
The above insertion and checking (delete on need basis) is done by
a thread, which is activated once in 30 seconds.
I am getting the following message in the console, which I don't know
how to handle. This message is appearing unpredictably, when trying
to delete the records (after deleting the records-?). However it is
correctly
deleting the records and the result is as per the expectation.
java.lang.ArrayIndexOutOfBoundsException: 1000 >= 1000
at java.util.Vector.elementAt(Unknown Source)
at javax.swing.table.DefaultTableModel.getValueAt(Unknown Source)
at javax.swing.JTable.getValueAt(Unknown Source)
at javax.swing.JTable.prepareRenderer(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paintCells(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paint(Unknown Source)
at javax.swing.plaf.ComponentUI.update(Unknown Source)
at javax.swing.JComponent.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JViewport.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintWithOffscreenBuffer(Unknown Source)
at javax.swing.JComponent.paintDoubleBuffered(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown
Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Any suggestion, will be of helpful.
Regards
Amaresh
 
Shashi Kanta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
post the code if its not too big
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look here. This thread talks about removing rows without getting exceptions.
 
Amaresh P
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sashi/Paul,
Here is the code. Kindly getback with fault with this code that creates the problem..
maxNumOfMsg = 1100;
maxNumOfFixMsg = 1000;
if ( mdl1.getRowCount() > maxNumOfMsg ) {
int irowCnt = mdl1.getRowCount();
int iNoOfRowsToBeDeleted = irowCnt-maxNumOfFixMsg;
for (int icntr = iNoOfRowsToBeDeleted - 1; icntr >= 0; icntr--)
deleteRow( mdl1,icntr );
}
if ( mdl2.getRowCount() > maxNumOfMsg ) {
int irowCnt = mdl2.getRowCount();
int iNoOfRowsToBeDeleted = irowCnt-maxNumOfFixMsg;
for (int icntr = iNoOfRowsToBeDeleted - 1; icntr >= 0; icntr--)
deleteRow( mdl2,icntr );
}
if ( mdl3.getRowCount() > maxNumOfMsg ) {
int irowCnt = mdl3.getRowCount();
int iNoOfRowsToBeDeleted = irowCnt-maxNumOfFixMsg;
for (int icntr = iNoOfRowsToBeDeleted - 1; icntr >= 0; icntr--)
deleteRow( mdl3,icntr );
mdl3.setRowCount(maxNumOfFixMsg);
}
public void deleteRow( SenjuTableModel mdlTable, int irowIndex ) {
try {
int seqId =
Integer.parseInt((String)((sjDataWithIcon)mdlTable.getValueAt(irowIndex,0)).
getData());
String date = (String)mdlTable.getValueAt(irowIndex,7);
if ( sLevel.isEntryPresent( sjSessionLevel.SHOKYO, seqId, date ) )
sLevel.removeEntry( sjSessionLevel.SHOKYO, seqId, date );
if ( sLevel.isEntryPresent( sjSessionLevel.KAKUNIN, seqId, date ) )
sLevel.removeEntry( sjSessionLevel.KAKUNIN, seqId, date );
mdlTable.removeRow(irowIndex);
deleteRecord( mdl4, seqId, date );
if (mdlTable == mdl1) deleteRecord( mdl5, seqId, date );
if (mdlTable == mdl2) deleteRecord( mdl6, seqId, date );
if (mdlTable == mdl3) deleteRecord( mdl7, seqId, date );
} catch (Exception e) { }
}
public void deleteRecord ( SenjuTableModel tblModel, int seqId, String
date ) {
try {
int irowCount = tblModel.getRowCount();
for ( int icntr = 0; icntr < irowCount; icntr++ ) {
if (seqId ==
Integer.parseInt((String)((sjDataWithIcon)tblModel.getValueAt(icntr,
0)).getData())) {
if (date.equals((String)tblModel.getValueAt(icntr, 7))) {
tblModel.removeRow(icntr);
break;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!