Name: jk109818 Date: 01/14/2003
FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
FULL OPERATING SYSTEM VERSION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
If you have selected the last item in a JList (in
SINGLE_SELECTION_MODE) and then remove one of the previous
items, then when you select one of the other remaining
items in the list, the last item is not repainted. It looks
as if it is still selected even though it is not. When a
repaint of that cell is forced (through minmizing or
resizing for example) then it repaints correctly.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run sample code
2. Select last item
3. Press delete button
4. Select one of the other remaining items
5. Resize or select last item to force repaint
EXPECTED VERSUS ACTUAL BEHAVIOR :
I would expect the last item to get repainted as not being
selected at step 4. It should not have to wait for a
repaint to be forced.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class ListTest2 extends JFrame {
private JScrollPane jScrollPane1 = new JScrollPane();
private JList jList1 = new JList();
private JButton btnDelete = new JButton();
public ListTest2() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel
(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e) {
e.printStackTrace();
}
ListTest2 listTest2 = new ListTest2();
}
private void jbInit() throws Exception {
btnDelete.setText("Delete");
btnDelete.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
btnDelete_actionPerformed(e);
}
});
DefaultListModel listMod = new DefaultListModel();
listMod.addElement("String1");
listMod.addElement("String2");
listMod.addElement("String3");
listMod.addElement("String4");
listMod.addElement("String5");
listMod.addElement("String6");
jList1.setModel(listMod);
jList1.setSelectionMode(
ListSelectionModel.SINGLE_SELECTION);
jScrollPane1.getViewport().add(jList1, null);
getContentPane().add(
jScrollPane1,
BorderLayout.CENTER);
getContentPane().add(btnDelete, BorderLayout.NORTH);
validate();
setVisible(true);
}
void btnDelete_actionPerformed(ActionEvent e) {
DefaultListModel listMod =
(DefaultListModel)jList1.getModel();
listMod.remove(0);
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
Create a ListSelectionListener that does a repaint in it's
valueChanged() method every time it gets a
ListSelectionEvent.
(Review ID: 180020)
======================================================================