-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
1.2.0
-
sparc
-
solaris_2.5
Name: dsC58869 Date: 04/13/98
The method java.awt.Choice.insert(String item) works wrong
while inserting 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("Insert new item between Item 0 and Item 1");
String newitem = "New Item";
ch.insert(newitem, 1);
System.out.println("Selected item : " + ch.getSelectedItem());
System.out.println("Selected index: " + ch.getSelectedIndex());
if(ch.getSelectedItem().equals(item1) && ch.getSelectedIndex() == 2)
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
Insert new item between Item 0 and Item 1
Selected item : Item 0
Selected index: 0
FAILED: selected item was changed
^C
======================================================================
Justification:
There is no reason to change selected item
======================================================================
- duplicates
-
JDK-4115156 problem with awt.Choice.insert()
-
- Closed
-