-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
1.3.0
-
x86
-
windows_2000
Name: boT120536 Date: 03/22/2001
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
Full source code to reproduce the problem is at the bottom of this message. The
important part is here:
I configured a JTable to allow only selection of a single column at a time:
final JTable jt = new JTable(data, columns);
jt.setRowSelectionAllowed(false);
jt.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jt.setColumnSelectionAllowed(true);
I then wrote a ListSelectionListener with the following method:
public void valueChanged(ListSelectionEvent e)
{
System.out.println(i++);
if(jt.getSelectedColumn() != 1)
{
jt.clearSelection();
}
}
Since the above method should be called every time the list selection changes,
unless the column selected is 1 the selection should be cleared. However if you
run the example code when you click column 1 and then one of the other columns,
about 1 in 3 times you can select a column other then 1. By watching the
console output while clicking you can see that in cases where you are allowed
to select a column other than 1, a ListSelectionEvent did not occur.
Full Source Code:
import javax.swing.*;
import javax.swing.event.*;
public class ListSelectionBug
{
public static void main(String[] args)
{
JFrame jf = new JFrame();
jf.setTitle("List Selection Bug Illustration");
jf.setSize(400, 400);
jf.setDefaultCloseOperation(jf.EXIT_ON_CLOSE);
String[] columns = new String[] {"Column 0", "Column
1", "Column 2", "Column 3", "Column 4"};
String[][] data = new String[10][columns.length];
for(int i=0; i<data.length; i++)
{
for(int i2=0; i2<data[0].length; i2++)
{
data[i][i2]=(i*i2)+"";
}
}
final JTable jt = new JTable(data, columns);
jt.setRowSelectionAllowed(false);
jt.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jt.setColumnSelectionAllowed(true);
jt.getSelectionModel().addListSelectionListener(new
ListSelectionListener()
{
int i=0;
public void valueChanged(ListSelectionEvent e)
{
System.out.println(i++);
if(jt.getSelectedColumn() != 1)
{
jt.clearSelection();
}
}
}
);
jf.getContentPane().add(new JScrollPane(jt));
jf.setVisible(true);
}
}
(Review ID: 119253)
======================================================================