|
-
October 13th, 1999, 04:24 AM
#1
JTable: Preventing cell from being edited.
I've got created JTable, and I'd like to prohibit cell's editing (make all cell read-only). How can I do this? Please, help!
Thanks in advance,
SY, SkyM
-
October 13th, 1999, 09:54 AM
#2
Re: JTable: Preventing cell from being edited.
isCellEditable() method of TableModel has to return false.
Try this ..
class CalendarTableModel extends AbstractTableModel{
String[] m_tColumnName = {"A" ,"B" , "C" , "D" , "E" , "F" , "G" };
int m_nRowCount = 0;
protected Vector dataVector;
public CalendarTableModel(){
dataVector = new Vector();
setNumRows(6);
}
public int getRowCount(){
return dataVector.size();
}
public int getColumnCount(){
return m_tColumnName.length;
}
public Object getValueAt( int nRow , int nColumn ){
Vector rowVector = (Vector)dataVector.elementAt(nRow);
return rowVector.elementAt(nColumn);
}
public void setValueAt( Object tValue ,int nRow , int nColumn ){
Vector rowVector = (Vector)dataVector.elementAt(nRow);
rowVector.setElementAt(tValue, nColumn);
// generate notification
fireTableChanged(new TableModelEvent(this, nRow , nRow , nColumn));
}
public String getColumnName( int nColumnIndex ){
return m_tColumnName[nColumnIndex];
}
public boolean isCellEditable( int nRow , int nColumn ){
return false;
}
public void setNumRows(int newSize) {
if ((newSize < 0) || (newSize == getRowCount()))
return;
int oldNumRows = getRowCount();
if (newSize <= getRowCount()) {
// newSize is smaller than our current size, so we can just
// let Vector discard the extra rows
dataVector.setSize(newSize);
// Generate notification
fireTableRowsDeleted(getRowCount(), oldNumRows-1);
}
else {
int columnCount = getColumnCount();
// We are adding rows to the model
while(getRowCount() < newSize) {
Vector newRow = new Vector(columnCount);
newRow.setSize(columnCount);
dataVector.addElement(newRow);
}
// Generate notification
fireTableRowsInserted(oldNumRows, getRowCount()-1);
}
}
}
I dont know a simple solution for this.
Poochi...
-
October 14th, 1999, 01:14 AM
#3
Re: JTable: Preventing cell from being edited.
-
October 19th, 1999, 11:28 PM
#4
Can you provide the full source code ?
can you provide the full source code for a working abstract model ?
thanks
http://members.xoom.com/lookads
-
October 19th, 1999, 11:59 PM
#5
Re: Can you provide the full source code ?
????? What's wrong with that code ? That's a fully working code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|