jQuery in Action, 2nd edition*
The moose likes Swing / AWT / SWT and the fly likes how  to Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "how  to "clear" jTable" Watch "how  to "clear" jTable" New topic
Author

how to "clear" jTable

miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
when i want to clear a textField i setText(""), but how to achieve it with a jTable?
i've a table that's populated from database with a custom tablemodel.
now i'm using table.setModel(DefaultTableModel), but that erases all column headers too, and i'd like to keep them

is there a proper way to achieve it? (I tried seting rs to null, but didnt work...)

TiA


java amateur
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

DefaultTableModel.setRowCount(0)?


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
DefaultTableModel.setRowCount(0)?

with default model doesnt work because i lose all headers, and with my model i'm totally unable to implement it...
(i can post it if needed)
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
here's what i'm trying:

and i always get
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
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.paintChildren(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.JComponent.paintChildren(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.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(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.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.seqPaintDirtyRegions(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.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(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)
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
as easy as:

miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
not that easy, after all
if my table scrolls down, then, after setting visible(false), the scrollbar still appears and if i scroll donw, rests of previous data appear ...
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Oh... sorry - I thought you were using a custom subclass of DefaultTableModel. Could you post the TableModel you are using?
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281

[ May 18, 2007: Message edited by: miguel lisboa ]
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
(i guess) i got it - added a setRowCount in model:

and in my gui:

so far it works fine...
 
 
subject: how to "clear" jTable
 
Similar Threads
How to add JLabel In a JTable cell
JTable
jtable
JTable Column
JTable Problem