EdwardWong
asked on
How to disable the Movement of JTable Column
JTable has a useful function that the User can move any Column as the like and JTable can reorganize it automatically. But for some reason,I need to disable this function. How can I do?
Now My method is:
class CustomModel extends DefaultTableModel {
public CustomModel(Object[][] data, Object[] columnNames) {
super(data, columnNames);
}
public Class getColumnClass(int col) {
// dataVector is a protected member of DefaultTableModel
Vector v = (Vector)dataVector.element At(0);
return v.elementAt(col).getClass( );
}
public boolean isCellEditable(int row, int column) {
if(column < 3)
return false;
else
return true;
}
}
CustomModel dataModel = new CustomModel(data,names);
JTable tblData = new JTable(dataModel);
But when using TableColumnModelListener,
it report an error.
Thank you very much.
Now My method is:
class CustomModel extends DefaultTableModel {
public CustomModel(Object[][] data, Object[] columnNames) {
super(data, columnNames);
}
public Class getColumnClass(int col) {
// dataVector is a protected member of DefaultTableModel
Vector v = (Vector)dataVector.element
return v.elementAt(col).getClass(
}
public boolean isCellEditable(int row, int column) {
if(column < 3)
return false;
else
return true;
}
}
CustomModel dataModel = new CustomModel(data,names);
JTable tblData = new JTable(dataModel);
But when using TableColumnModelListener,
it report an error.
Thank you very much.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>Anonymous class of method jbinit() should be declared abstract, it does not define method columnSelectionChanged
>(javax.swing.event.ListSe
It seems you have not implement the
TableColumnModelListener()
You have to implement all the functions(5) in TableColumnModelListener when you try to implement this interface.
table.getColumnModel().add
public void columnAdded(TableColumnMod
public void columnMarginChanged(Change
public void columnMoved(TableColumnMod
public void columnRemoved(TableColumnM
public void columnSelectionChanged(Lis
});
Sankar S.
ASKER
No, I implement all the functions(5) in tableColumnModelListener, As below:
table.getColumnModel().add ColumnMode lListener( new TableColumnModelListener() {
public void columnAdded(TableColumnMod elEvent e){}
public void columnMarginChanged(Change Event e){}
public void columnMoved(TableColumnMod elEvent e){
table.getTableMode()...
^^^^^^^^^^^^^^^^^^^^^^^^^^ ^
}
public void columnRemoved(TableColumnM odelEvent e){}
public void columnSelectionChanged(Lis tSelection Event e){}
});
I think if in the Implementation Java doesn't allow user to cite the table it self.
table.getColumnModel().add
public void columnAdded(TableColumnMod
public void columnMarginChanged(Change
public void columnMoved(TableColumnMod
table.getTableMode()...
^^^^^^^^^^^^^^^^^^^^^^^^^^
}
public void columnRemoved(TableColumnM
public void columnSelectionChanged(Lis
});
I think if in the Implementation Java doesn't allow user to cite the table it self.
ASKER
What error are you getting and how do you use it?
^^^^^^^^^^^^^^^^^^^^^^^^^^
I use
"table.getColumnModel().ad
.........}); "
in init() Function.
The java compiler reports an error, as below:
Anonymous class of method jbinit() should be declared abstract, it does not define method columnSelectionChanged(jav
Thank you for your help.