下面列出了javax.swing.table.TableCellEditor#addCellEditorListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public boolean editCellAt(int index, EventObject e) {
if (cellEditor != null && !cellEditor.stopCellEditing()) {
return false;
}
if (!isCellEditable(index)) {
return false;
}
TableCellEditor editor = getCellEditor(index);
if (editor != null && editor.isCellEditable(e)) {
editorComp = prepareEditor(editor, index);
editorComp.setBounds(getHeaderRect(index));
add(editorComp);
editorComp.validate();
setCellEditor(editor);
setEditingColumn(index);
editor.addCellEditorListener(this);
return true;
}
return false;
}
public boolean editCellAt( final int index, final EventObject e ) {
if ( cellEditor != null && !cellEditor.stopCellEditing() ) {
return false;
}
if ( !isCellEditable( index ) ) {
return false;
}
final TableCellEditor editor = getCellEditor( index );
if ( editor != null && editor.isCellEditable( e ) ) {
editorComp = prepareEditor( editor, index );
editorComp.setBounds( getHeaderRect( index ) );
add( editorComp );
editorComp.validate();
setCellEditor( editor );
setEditingColumn( index );
editor.addCellEditorListener( this );
return true;
}
return false;
}
public boolean editCellAt(int index, EventObject e){
if (cellEditor != null && !cellEditor.stopCellEditing()) {
return false;
}
if (!isCellEditable(index)) {
return false;
}
TableCellEditor editor = getCellEditor(index);
if (editor != null && editor.isCellEditable(e)) {
editorComp = prepareEditor(editor, index);
editorComp.setBounds(getHeaderRect(index));
add(editorComp);
editorComp.validate();
setCellEditor(editor);
setEditingColumn(index);
editor.addCellEditorListener(this);
return true;
}
return false;
}
/**
* Add the specified listener to <em>all</em> the delegate editors.
* @param l the listener to add
*/
@Override
public void addCellEditorListener(CellEditorListener l) {
for(TableCellEditor e : editors) {
e.addCellEditorListener(l);
}
}
/**
* Programmatically starts editing the cell at <code>row</code> and <code>column</code>, if
* those indices are in the valid range, and the cell at those indices is editable. To prevent
* the <code>JTable</code> from editing a particular table, column or cell value, return false
* from the <code>isCellEditable</code> method in the <code>TableModel</code> interface.
*
* @param row
* the row to be edited
* @param column
* the column to be edited
* @param e
* event to pass into <code>shouldSelectCell</code>; note that as of Java 2 platform
* v1.2, the call to <code>shouldSelectCell</code> is no longer made
* @return false if for any reason the cell cannot be edited, or if the indices are invalid
*/
@Override
public boolean editCellAt(int row, int column, EventObject e) {
if (cellEditor != null && !cellEditor.stopCellEditing()) {
return false;
}
if (row < 0 || row >= getRowCount() || column < 0 || column >= getColumnCount()) {
return false;
}
if (!isCellEditable(row, column)) {
return false;
}
TableCellEditor editor = getCellEditor(row, column);
if (editor != null && editor.isCellEditable(e)) {
editorComp = prepareEditor(editor, row, column);
if (editorComp == null) {
removeEditor();
return false;
}
editorComp.setBounds(getCellRect(row, column, false));
add(editorComp);
editorComp.validate();
editorComp.repaint();
setCellEditor(editor);
setEditingRow(row);
setEditingColumn(column);
editor.addCellEditorListener(this);
return true;
}
return false;
}
public void setCellEditor(TableCellEditor newEditor) {
TableCellEditor oldEditor = cellEditor;
cellEditor = newEditor;
// firePropertyChange
if (oldEditor != null) {
oldEditor.removeCellEditorListener(this);
}
if (newEditor != null) {
newEditor.addCellEditorListener(this);
}
}
public void setCellEditor( final TableCellEditor newEditor ) {
final TableCellEditor oldEditor = cellEditor;
cellEditor = newEditor;
if ( oldEditor != null ) {
oldEditor.removeCellEditorListener( this );
}
if ( newEditor != null ) {
newEditor.addCellEditorListener( this );
}
}