本文整理汇总了Java中javax.swing.JTable.getCellEditor方法的典型用法代码示例。如果您正苦于以下问题:Java JTable.getCellEditor方法的具体用法?Java JTable.getCellEditor怎么用?Java JTable.getCellEditor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JTable
的用法示例。
在下文中一共展示了JTable.getCellEditor方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: actionPerformed
import javax.swing.JTable; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent ae) {
JTable jt = (JTable) ae.getSource();
if (jt != null) {
if (jt.isEditing()) {
TableCellEditor tce = jt.getCellEditor();
if (PropUtils.isLoggable(BaseTable.class)) {
PropUtils.log(BaseTable.class, "Cancelling edit due to keyboard event"); //NOI18N
}
if (tce != null) {
jt.getCellEditor().cancelCellEditing();
}
} else {
//If we're in a dialog, try to close it
trySendEscToDialog(jt);
}
}
}
示例2: renameDomainInComponents
import javax.swing.JTable; //导入方法依赖的package包/类
/**
* Rename domain in components.
*
* @param oldDomainName the old domain name
* @param newDomainName the new domain name
*/
public void renameDomainInComponents(String oldDomainName, String newDomainName) {
DefaultTableModel dtmComponents = this.getTableModel4ComponentTypes();
int column = getColumnHeaderIndexComponents(COL_Domain);
// --- Get the component type definitions from table ----
JTable jtComponents = this.getJTable4ComponentTypes();
// --- Confirm, apply changes in table ------------------
TableCellEditor tceComponents = jtComponents.getCellEditor();
if (tceComponents!=null) {
tceComponents.stopCellEditing();
}
for(int row=0; row<dtmComponents.getRowCount(); row++){
String currValue = (String) dtmComponents.getValueAt(row, column);
if (currValue.equals(oldDomainName)) {
dtmComponents.setValueAt(newDomainName, row, column);
}
}
this.setTableCellEditor4DomainsInComponents(null);
}
示例3: mouseClicked
import javax.swing.JTable; //导入方法依赖的package包/类
@Override
public void mouseClicked(MouseEvent e) {
JTableHeader h = (JTableHeader) e.getSource();
JTable table = h.getTable();
int selectedRow = table.getSelectedRow();
TableModel model = table.getModel();
//remember selection to keep after sorting
Object selectedAction=null;
int objectColumn=-1;
if(selectedRow>-1) {
for(int i=0; i<table.getColumnCount(); i++) {
//first find colum with appropriate object
if(model.getValueAt(selectedRow, i) instanceof ActionHolder) {
//remember this object
selectedAction=model.getValueAt(selectedRow, i);
objectColumn=i;
//stop edition as we click somewhere ouside of editor
TableCellEditor editor=table.getCellEditor();
if(editor!=null) {
editor.stopCellEditing();
}
break;
}
}
}
TableColumnModel columnModel = h.getColumnModel();
int viewColumn = columnModel.getColumnIndexAtX(e.getX());
int column = columnModel.getColumn(viewColumn).getModelIndex();
if (column != -1) {
int status = getSortingStatus(column);
if (!e.isControlDown()) {
cancelSorting();
}
// Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or
// {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed.
status = status + (e.isShiftDown() ? -1 : 1);
status = (status + 4) % 3 - 1; // signed mod, returning {-1, 0, 1}
setSortingStatus(column, status);
//reselect the same object
if(selectedAction!=null)setSelectedRow(table, selectedAction, objectColumn);
}
}
示例4: testEditors
import javax.swing.JTable; //导入方法依赖的package包/类
public void testEditors() {
setUpModel();
JTable t = ot.treeTable.getTable();
ot.revalidate();
javax.swing.JFrame f = new javax.swing.JFrame();
f.setLayout(new BorderLayout());
f.add(ot, BorderLayout.CENTER);
f.setSize(600, 500);
f.setVisible(true);
//while (f.isVisible()) {
try {
Thread.sleep(333);
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
}
//}
System.out.println("table rows = "+t.getRowCount());
TableCellEditor tce = t.getCellEditor(0, 0);
assertTrue(tce+"is not editable.", tce.isCellEditable(getMouseClickAt(t, 0, 0)));
//assertTrue(t+"is not editable.", t.isCellEditable(0, 0));
Component c = tce.getTableCellEditorComponent(t, null, true, 0, 0);
//System.err.println("c = "+c);
assertTrue("Editor component = "+c, c instanceof EditorComponent);
assertEquals("Editor of 0:DN", ((EditorComponent) c).getText());
tce = t.getCellEditor(0, 1);
assertTrue(tce+"is not editable.", tce.isCellEditable(getMouseClickAt(t, 0, 1)));
assertTrue(t+"is not editable.", t.isCellEditable(0, 1));
c = tce.getTableCellEditorComponent(t, null, true, 0, 1);
assertTrue("Editor component = "+c, c instanceof EditorComponent);
assertEquals("Editor of 0:col1", ((EditorComponent) c).getText());
tce = t.getCellEditor(0, 2);
assertTrue(tce+"is not editable.", tce.isCellEditable(getMouseClickAt(t, 0, 2)));
assertTrue(t+"is not editable.", t.isCellEditable(0, 2));
c = tce.getTableCellEditorComponent(t, null, true, 0, 2);
assertTrue("Editor component = "+c, c instanceof EditorComponent);
assertEquals("Editor of 0:col2", ((EditorComponent) c).getText());
tce = t.getCellEditor(1, 0);
assertFalse(tce+"is editable.", tce.isCellEditable(getMouseClickAt(t, 1, 0)));
assertFalse(t+"is editable.", t.isCellEditable(1, 0));
c = tce.getTableCellEditorComponent(t, null, true, 1, 0);
assertFalse("Editor component = "+c, c instanceof EditorComponent);
tce = t.getCellEditor(1, 2);
assertFalse(tce+"is editable.", tce.isCellEditable(getMouseClickAt(t, 1, 2)));
assertFalse(t+"is editable.", t.isCellEditable(1, 2));
c = tce.getTableCellEditorComponent(t, null, true, 1, 2);
assertFalse("Editor component = "+c, c instanceof EditorComponent);
tce = t.getCellEditor(3, 1);
assertTrue(tce+"is not editable.", tce.isCellEditable(getMouseClickAt(t, 3, 1)));
assertTrue(t+"is not editable.", t.isCellEditable(3, 1));
c = tce.getTableCellEditorComponent(t, null, true, 3, 1);
assertTrue("Editor component = "+c, c instanceof EditorComponent);
assertEquals("Editor of 3:col1", ((EditorComponent) c).getText());
tce = t.getCellEditor(6, 0);
assertTrue(tce+"is not editable.", tce.isCellEditable(getMouseClickAt(t, 6, 0)));
assertTrue(t+"is not editable.", t.isCellEditable(6, 0));
c = tce.getTableCellEditorComponent(t, null, true, 6, 0);
assertTrue("Editor component = "+c, c instanceof EditorComponent);
assertEquals("Editor of 6:DN", ((EditorComponent) c).getText());
tce = t.getCellEditor(9, 2);
assertTrue(tce+"is not editable.", tce.isCellEditable(getMouseClickAt(t, 9, 2)));
assertTrue(t+"is not editable.", t.isCellEditable(9, 2));
c = tce.getTableCellEditorComponent(t, null, true, 9, 2);
assertTrue("Editor component = "+c, c instanceof EditorComponent);
assertEquals("Editor of 9:col2", ((EditorComponent) c).getText());
}
示例5: cancelEditing
import javax.swing.JTable; //导入方法依赖的package包/类
/**
* stops the tmodel cell editing
*
* @param table the target tmodel
*/
public static void cancelEditing(JTable table) {
if (table.getCellEditor() != null) {
table.getCellEditor().cancelCellEditing();
}
}
示例6: stopEditing
import javax.swing.JTable; //导入方法依赖的package包/类
public static void stopEditing(JTable table) {
if (null != table.getCellEditor()) {
table.getCellEditor().stopCellEditing();
}
}