下面列出了怎么用javax.swing.CellEditor的API类实例代码及写法,或者点击链接到github查看源代码。
public void actionPerformed(ActionEvent e) {
JTable table = (JTable)e.getSource();
if (!table.hasFocus()) {
CellEditor cellEditor = table.getCellEditor();
if (cellEditor != null && !cellEditor.stopCellEditing()) { return; }
table.requestFocus();
return;
}
ListSelectionModel rsm = table.getSelectionModel();
int anchorRow = rsm.getAnchorSelectionIndex();
table.editCellAt(anchorRow, PropertySheetTableModel.VALUE_COLUMN);
Component editorComp = table.getEditorComponent();
if (editorComp != null) {
editorComp.requestFocus();
}
}
public TableEditorTable(List<Attribute> attributes, GUIFramework framework) {
this.framework = framework;
this.attributes = attributes;
plugins = new AttributePlugin[attributes.size()];
cellEditors = new TableCellEditor[plugins.length];
cellRenderers = new TableCellRenderer[plugins.length];
setHorizontalScrollEnabled(true);
setShowVerticalLines(true);
getInputMap(JInternalFrame.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
"RamusENTER_Action");
getInputMap(JInternalFrame.WHEN_FOCUSED).put(
KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
"RamusENTER_Action");
AbstractAction ramusEnterAction = new AbstractAction() {
/**
*
*/
private static final long serialVersionUID = 4745861738845278043L;
public void actionPerformed(ActionEvent ae) {
CellEditor editor = getCellEditor();
if (editor != null)
editor.stopCellEditing();
}
};
getActionMap().put("RamusENTER_Action", ramusEnterAction);
}