-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
1.2.0
-
sparc
-
solaris_2.5
Name: dsC58869 Date: 04/09/98
The method java.awt.Choice.remove(String item) works wrong
while removing non-selected item. It should adjust the selected item index,
otherwise the selected item may change.
==== Here is the test demonstrating the bug ====
import java.awt.*;
public class Test{
public static void main(String[] args){
String item0 = "Item 0";
String item1 = "Item 1";
String item2 = "Item 2";
Choice ch = new Choice();
ch.add(item0);
ch.add(item1);
ch.add(item2);
ch.select(item1);
System.out.println("Selected item : " + ch.getSelectedItem());
System.out.println("Selected index: " + ch.getSelectedIndex());
System.out.println("Remove Item 0");
ch.remove(item0);
System.out.println("Selected item : " + ch.getSelectedItem());
System.out.println("Selected index: " + ch.getSelectedIndex());
if(ch.getSelectedItem().equals(item1) && ch.getSelectedIndex() == 0)
System.out.println("OKAY");
else
System.out.println("FAILED: selected item was changed");
}
}
==== Here is the output of the test ====
%java Test
Selected item : Item 1
Selected index: 1
Remove Item 0
Selected item : Item 2
Selected index: 1
FAILED: selected item was changed
^C
======================================================================
Justification:
There is no reason to change selected item
======================================================================
- duplicates
-
JDK-4115139 problem with awt.Choice.remove()
- Closed