author | mfang |
Wed, 17 Aug 2011 14:18:26 -0700 | |
changeset 10294 | 8fcdae2a7ec7 |
parent 7668 | d4a77089c587 |
child 28071 | 3acb75b8df45 |
permissions | -rw-r--r-- |
5955
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
1 |
/* |
7668 | 2 |
* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. |
5955
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
4 |
* |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
8 |
* |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
13 |
* accompanied this code). |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
14 |
* |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
18 |
* |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
21 |
* questions. |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
22 |
*/ |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
23 |
|
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
24 |
/* @test |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
25 |
@bug 6711682 |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
26 |
@summary JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
27 |
@author Alexander Potochkin |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
28 |
@run main bug6711682 |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
29 |
*/ |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
30 |
|
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
31 |
import sun.awt.SunToolkit; |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
32 |
|
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
33 |
import javax.swing.*; |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
34 |
import javax.swing.event.CellEditorListener; |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
35 |
import javax.swing.table.TableCellEditor; |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
36 |
import javax.swing.table.TableCellRenderer; |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
37 |
import java.awt.*; |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
38 |
import java.awt.event.InputEvent; |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
39 |
import java.awt.event.KeyEvent; |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
40 |
import java.util.EventObject; |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
41 |
|
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
42 |
public class bug6711682 { |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
43 |
private static JCheckBox editorCb; |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
44 |
private static JCheckBox rendererCb; |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
45 |
private static JTable table; |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
46 |
|
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
47 |
public static void main(String[] args) throws Exception { |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
48 |
Robot robot = new Robot(); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
49 |
robot.setAutoDelay(50); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
50 |
SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
51 |
SwingUtilities.invokeAndWait(new Runnable() { |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
52 |
public void run() { |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
53 |
createAndShowGUI(); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
54 |
} |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
55 |
}); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
56 |
toolkit.realSync(); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
57 |
Point l = table.getLocationOnScreen(); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
58 |
int h = table.getRowHeight(); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
59 |
for (int i = 0; i < 3; i++) { |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
60 |
robot.mouseMove(l.x + 5, l.y + 5 + i * h); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
61 |
robot.mousePress(InputEvent.BUTTON1_MASK); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
62 |
robot.mouseRelease(InputEvent.BUTTON1_MASK); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
63 |
} |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
64 |
// Without pressing F2 the last table's cell |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
65 |
// reported <code>false</code> value |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
66 |
// note that I can't press it inside the for loop |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
67 |
// because it doesn't reproduce the bug |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
68 |
robot.keyPress(KeyEvent.VK_F2); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
69 |
robot.keyRelease(KeyEvent.VK_F2); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
70 |
|
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
71 |
for (int i = 0; i < 3; i++) { |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
72 |
if (!Boolean.TRUE.equals(table.getValueAt(i, 0))) { |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
73 |
throw new RuntimeException("Row #" + i + " checkbox is not selected"); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
74 |
} |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
75 |
} |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
76 |
for (int i = 2; i >= 0; i--) { |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
77 |
robot.mouseMove(l.x + 5, l.y + 5 + i * h); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
78 |
robot.mousePress(InputEvent.BUTTON1_MASK); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
79 |
robot.mouseRelease(InputEvent.BUTTON1_MASK); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
80 |
} |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
81 |
robot.keyPress(KeyEvent.VK_F2); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
82 |
robot.keyRelease(KeyEvent.VK_F2); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
83 |
for (int i = 0; i < 3; i++) { |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
84 |
if (Boolean.TRUE.equals(table.getValueAt(i, 0))) { |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
85 |
throw new RuntimeException("Row #" + i + " checkbox is selected"); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
86 |
} |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
87 |
} |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
88 |
} |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
89 |
|
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
90 |
private static void createAndShowGUI() { |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
91 |
editorCb = new JCheckBox(); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
92 |
rendererCb = new JCheckBox(); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
93 |
JFrame f = new JFrame("Table with CheckBox"); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
94 |
Container p = f.getContentPane(); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
95 |
p.setLayout(new BorderLayout()); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
96 |
table = new JTable(new Object[][]{{false}, {false}, {false}}, new Object[]{"CheckBox"}); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
97 |
TableCellEditor editor = new TableCellEditor() { |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
98 |
int editedRow; |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
99 |
|
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
100 |
public Component getTableCellEditorComponent(JTable table, |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
101 |
Object value, boolean isSelected, int row, int column) { |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
102 |
this.editedRow = row; |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
103 |
editorCb.setSelected(Boolean.TRUE.equals(value)); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
104 |
editorCb.setBackground(UIManager.getColor("Table.selectionBackground")); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
105 |
return editorCb; |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
106 |
} |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
107 |
|
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
108 |
public void addCellEditorListener(CellEditorListener l) { |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
109 |
} |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
110 |
|
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
111 |
public void cancelCellEditing() { |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
112 |
} |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
113 |
|
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
114 |
public Object getCellEditorValue() { |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
115 |
return editorCb.isSelected(); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
116 |
} |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
117 |
|
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
118 |
public boolean isCellEditable(EventObject anEvent) { |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
119 |
return true; |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
120 |
} |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
121 |
|
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
122 |
public void removeCellEditorListener(CellEditorListener l) { |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
123 |
} |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
124 |
|
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
125 |
public boolean shouldSelectCell(EventObject anEvent) { |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
126 |
return true; |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
127 |
} |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
128 |
|
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
129 |
public boolean stopCellEditing() { |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
130 |
table.getModel().setValueAt(editorCb.isSelected(), editedRow, 0); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
131 |
return true; |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
132 |
} |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
133 |
}; |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
134 |
table.getColumnModel().getColumn(0).setCellEditor(editor); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
135 |
|
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
136 |
TableCellRenderer renderer = new TableCellRenderer() { |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
137 |
public Component getTableCellRendererComponent(JTable table, |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
138 |
Object value, boolean isSelected, boolean hasFocus, |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
139 |
int row, int column) { |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
140 |
rendererCb.setSelected(Boolean.TRUE.equals(value)); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
141 |
return rendererCb; |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
142 |
} |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
143 |
}; |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
144 |
table.getColumnModel().getColumn(0).setCellRenderer(renderer); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
145 |
|
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
146 |
p.add(table, BorderLayout.CENTER); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
147 |
|
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
148 |
f.pack(); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
149 |
f.setVisible(true); |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
150 |
} |
94a5ce4a297b
6711682: JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click
alexp
parents:
diff
changeset
|
151 |
} |