估计你已经找到正确答案了。。
public class TableWithOverwrite extends JTable {
public final static String EXCLUDE = "F2";
private boolean isBlankEditor = false;
public TableWithOverwrite() {
super();
}
public TableWithOverwrite(TableModel tm) {
super(tm);
}
@Override
public Component prepareEditor(TableCellEditor editor, int row, int column) {
Component c = super.prepareEditor(editor, row, column);
if (isBlankEditor)
((JTextField) c).setText("");
return c;
}
@Override
protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) {
if (! EXCLUDE.equals(KeyEvent.getKeyText(e.getKeyCode())))
isBlankEditor = true;
boolean retValue = super.processKeyBinding(ks, e, condition, pressed);
isBlankEditor = false;
return retValue;
}
}
温馨提示:答案为网友推荐,仅供参考