Name: gm110360 Date: 04/24/2002
FULL PRODUCT VERSION :
java version "1.4.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b84)
Java HotSpot(TM) Client VM (build 1.4.0-beta3-b84, mixed mode)
FULL OPERATING SYSTEM VERSION :
glibc-2.1.3-15
A DESCRIPTION OF THE PROBLEM :
JTables offer built-in support for columns containing
JCheckBoxes. In contrast to other table cell editors which
are activated with a mouse-click, check box table cell
editors have a special behavior to immediatly switch on
every mouse-click. This works fine since JDK1.3, but if
one uses the new JDK1.4 feature to drag-enable the JTable,
there is a problem. If the row containing the check box
already has the focus, the first mouse click is ignored
and only every other mouse-click actually toggles the
check box.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Compile and start the program contained in the "source
code" field.
2. Click on the (already checked) check box in the first
row, second column. The box is unchecked as expected.
3. Click on the same check box again. Nothing happens.
4. Click on the same check box again. The box is checked
again.
EXPECTED VERSUS ACTUAL BEHAVIOR :
The check box should be toggled on every mouse click.
This works fine if the line
table.setDragEnabled(true);
is commented-out in the source code given below.
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.*;
import javax.swing.table.*;
public class JCheckBoxInJTableBug extends JFrame {
public JCheckBoxInJTableBug() {
final JTable table=new JTable(new TestTableModel());
table.setDragEnabled(true);
getContentPane().add(table);
pack();
}
public static void main(String[] args) {
new JCheckBoxInJTableBug().show();
}
static class TestTableModel extends DefaultTableModel {
TestTableModel() {
super(new Object[][]{{"foo",Boolean.TRUE},{"bar",Boolean.FALSE}},
new Object[]{"string","boolean"});
}
public Class getColumnClass(int columnIndex) {
if (columnIndex==1)
return Boolean.class;
else
return super.getColumnClass(columnIndex);
}
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
Write your own check box table cell editor.
(Review ID: 138074)
======================================================================