-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathEditableCellFocusAction.java
More file actions
57 lines (45 loc) · 1.3 KB
/
EditableCellFocusAction.java
File metadata and controls
57 lines (45 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.awt.event.*;
import javax.swing.*;
public class EditableCellFocusAction extends WrappedAction implements ActionListener
{
private JTable table;
/*
* Specify the component and KeyStroke for the Action we want to wrap
*/
public EditableCellFocusAction(JTable table, KeyStroke keyStroke)
{
super(table, keyStroke);
this.table = table;
}
/*
* Provide the custom behaviour of the Action
*/
public void actionPerformed(ActionEvent e)
{
int originalRow = table.getSelectedRow();
int originalColumn = table.getSelectedColumn();
invokeOriginalAction( e );
int row = table.getSelectedRow();
int column = table.getSelectedColumn();
// Keep invoking the original action until we find an editable cell
while (! table.isCellEditable(row, column) )
{
invokeOriginalAction( e );
// We didn't move anywhere, reset cell selection and get out.
if (row == table.getSelectedRow()
&& column == table.getSelectedColumn())
{
table.changeSelection(originalRow, originalColumn, false, false);
break;
}
row = table.getSelectedRow();
column = table.getSelectedColumn();
// Back to where we started, get out.
if (row == originalRow
&& column == originalColumn)
{
break;
}
}
}
}