Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do i stop users from moving column in JTable? 1

Status
Not open for further replies.

dellyjm

Programmer
Apr 13, 2000
168
JM
Hi does anyone know how to stop users from moving a column in JTable whilst making the cells editable still?

Delton
 
It helped immensely.

One more question Flumpy, do you know how to clear the values of the table (cell values)?

Delton.
 
use the TableModel?

TableModel myTM = myJTable.getTableModel();

for(int x = 0;x < myTM.getRowCount();x++)
for(int y = 0; y < myTM.getColumnCount();y++)
myTM.setValueAt(&quot;&quot;, x, y);


this example only works for a table of strings. same principle tho, as setValueAt(Object o, int row, int col) accepts any object.

hope that helps.

matt
 
Yes it does, it was what I was doing originally. I was just wondering if I could completely remove the row. Thanks.

Delton.
 
The JTable object uses a TableModel, often there is no need to use a table model other than the default, in whioh case the following will work.

Code:
TableModel tm = JTable.getModel();
if(tm instanceof DefaultTableModel) {
  ((DefaultTableModel)tm).removeRow(rowNumber)
}
else {
  // Hmmm, don't know how to remove row.
}

 
wont that actually remove the entire row, not just the contents tho?
 
Erm, yes, but isn't that what dellyjm wanted; &quot;I was just wondering if I could completely remove the row&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top