-
Bug
-
Resolution: Unresolved
-
P3
-
11, 17, 21, 25
-
None
-
generic
-
os_x
On macOS, when a List component is added to a Frame, it may lose its previous selections. This happens even if the list was set to allow multiple selections.
In the example below, selecting two items works at first. But after adding the list to the frame, the first selection is lost when selecting another item.
This does not happen if the list is not added to the frame.
import java.awt.Frame;
import java.awt.List;
import java.util.Arrays;
public class ListSelectionBug {
public static void main(String[] args) {
Frame frame = new Frame();
List list = new List(4, true); // multi-selection list
list.add("Item1");
list.add("Item2");
System.out.println("selected " + Arrays.toString(list.getSelectedIndexes()));
list.select(0); // select first item
System.out.println("selected " + Arrays.toString(list.getSelectedIndexes()));
list.select(1); // select second item
System.out.println("selected " + Arrays.toString(list.getSelectedIndexes()));
frame.add(list); // comment out this line to avoid the bug
frame.pack();
System.out.println("selected " + Arrays.toString(list.getSelectedIndexes()));
list.select(1); // BUG: selection of first item is lost
System.out.println("selected " + Arrays.toString(list.getSelectedIndexes()));
frame.dispose();
}
}
In the example below, selecting two items works at first. But after adding the list to the frame, the first selection is lost when selecting another item.
This does not happen if the list is not added to the frame.
import java.awt.Frame;
import java.awt.List;
import java.util.Arrays;
public class ListSelectionBug {
public static void main(String[] args) {
Frame frame = new Frame();
List list = new List(4, true); // multi-selection list
list.add("Item1");
list.add("Item2");
System.out.println("selected " + Arrays.toString(list.getSelectedIndexes()));
list.select(0); // select first item
System.out.println("selected " + Arrays.toString(list.getSelectedIndexes()));
list.select(1); // select second item
System.out.println("selected " + Arrays.toString(list.getSelectedIndexes()));
frame.add(list); // comment out this line to avoid the bug
frame.pack();
System.out.println("selected " + Arrays.toString(list.getSelectedIndexes()));
list.select(1); // BUG: selection of first item is lost
System.out.println("selected " + Arrays.toString(list.getSelectedIndexes()));
frame.dispose();
}
}
- links to
-
Review(master) openjdk/jdk/27682