45 |
import java.awt.Rectangle; |
import java.awt.Rectangle; |
46 |
import java.awt.event.ActionEvent; |
import java.awt.event.ActionEvent; |
47 |
import java.awt.event.ActionListener; |
import java.awt.event.ActionListener; |
48 |
|
import java.awt.event.KeyAdapter; |
49 |
|
import java.awt.event.KeyEvent; |
50 |
import java.text.DateFormat; |
import java.text.DateFormat; |
51 |
import java.text.NumberFormat; |
import java.text.NumberFormat; |
52 |
import java.util.Date; |
import java.util.Date; |
578 |
Timer editorTimer = new EditorUpdateTimer(); |
Timer editorTimer = new EditorUpdateTimer(); |
579 |
|
|
580 |
/** |
/** |
581 |
|
* Stores the old value of a cell before it was edited, in case |
582 |
|
* editing is cancelled |
583 |
|
*/ |
584 |
|
Object oldCellValue; |
585 |
|
|
586 |
|
/** |
587 |
* Creates a new <code>JTable</code> instance. |
* Creates a new <code>JTable</code> instance. |
588 |
*/ |
*/ |
589 |
public JTable () |
public JTable () |
846 |
|
|
847 |
public void editingCanceled (ChangeEvent event) |
public void editingCanceled (ChangeEvent event) |
848 |
{ |
{ |
849 |
|
if (rowBeingEdited > -1 && columnBeingEdited > -1) |
850 |
|
{ |
851 |
|
if (getValueAt(rowBeingEdited, columnBeingEdited) instanceof JTextField) |
852 |
|
{ |
853 |
|
remove ((Component)getValueAt(rowBeingEdited, columnBeingEdited)); |
854 |
|
setValueAt(oldCellValue, rowBeingEdited, columnBeingEdited); |
855 |
|
} |
856 |
|
rowBeingEdited = -1; |
857 |
|
columnBeingEdited = -1; |
858 |
|
} |
859 |
|
editorTimer.stop(); |
860 |
|
editorComp = null; |
861 |
|
cellEditor = null; |
862 |
|
requestFocusInWindow(false); |
863 |
repaint(); |
repaint(); |
864 |
} |
} |
865 |
|
|
2319 |
*/ |
*/ |
2320 |
public boolean editCellAt (int row, int column) |
public boolean editCellAt (int row, int column) |
2321 |
{ |
{ |
2322 |
|
oldCellValue = getValueAt(row, column); |
2323 |
setCellEditor(getCellEditor(row, column)); |
setCellEditor(getCellEditor(row, column)); |
2324 |
editorComp = prepareEditor(cellEditor, row, column); |
editorComp = prepareEditor(cellEditor, row, column); |
2325 |
|
editorComp.addKeyListener(new KeyAdapter() { |
2326 |
|
public void keyPressed(KeyEvent e) { |
2327 |
|
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { |
2328 |
|
if (JTable.this.cellEditor != null) |
2329 |
|
JTable.this.cellEditor.cancelCellEditing(); |
2330 |
|
} |
2331 |
|
} |
2332 |
|
}); |
2333 |
cellEditor.addCellEditorListener(this); |
cellEditor.addCellEditorListener(this); |
2334 |
rowBeingEdited = row; |
rowBeingEdited = row; |
2335 |
columnBeingEdited = column; |
columnBeingEdited = column; |