Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Problem in JTable

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
post the code if its not too big
 
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();
}
}
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic