使用AbstractCellEditor做一个JComboBox表格单元格编辑器,需要重写哪个方法才能使编辑器停止编辑?要怎样重写,谢谢。
代码如下:
public class MyTableEditor extends AbstractCellEditor implements
TableCellEditor
{ JComboBox comboBox = new JComboBox();
public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected, int row, int column)
{
comboBox.addItem("1");
comboBox.addItem("2");
comboBox.addItem("3");
return comboBox;
} public Object getCellEditorValue()
{
return comboBox.getSelectedItem();
}
}
代码如下:
public class MyTableEditor extends AbstractCellEditor implements
TableCellEditor
{ JComboBox comboBox = new JComboBox();
public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected, int row, int column)
{
comboBox.addItem("1");
comboBox.addItem("2");
comboBox.addItem("3");
return comboBox;
} public Object getCellEditorValue()
{
return comboBox.getSelectedItem();
}
}
public boolean stopCellEditing()public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected,
int row, int column);
isEditable() 如果 JComboBox 可编辑,则返回 true。
setEditable(boolean aFlag) 确定 JComboBox 字段是否可编辑。