Re: Problem with JTable and DefaultCellEditor
Thank you Steve. I actually got some ideas from the Sun Swing forum.
The following code is based on that:
package swing.table;
import java.awt.Component;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableModel;
import javax.swing.text.JTextComponent;
import client.EditorState;
public class MyTable extends JTable {
public MyTable(TableModel dm) {
super(dm);
}
public Component prepareEditor(TableCellEditor editor, int row, int
col) {
//If the cell is JComboBox then default behaviour is same as
super class.
if(col == 2) {
return super.prepareEditor(editor, row, col);
}
JTextComponent comp = (JTextComponent)
super.prepareEditor(editor, row, col);
//The setText method makes the old value disappear when a user
starts typing in a
// cell
if(!EditorState.getInstance().isRestoreInProgress()) {
comp.setText(null);
}
return comp;
}
}
This table allows the selection of cells in a table. This works fine in
most cases. The problem is that when I select a particular cell in a
table and open another table to display the data, it copies the value
of the old table's cell into the newly opened table cell.
How do I avoid this unwanted copy of old data? Thanks in advance.
BP
http://www.ProblemSolvingSkill.net