1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
/* Insert Item At Specified Index In AWT Choice Or Combobox Example This java example shows how to insert a particular item at specified index in a choice or a combobox control using insert method of AWT Choice class. */ import java.applet.Applet; import java.awt.Choice; /* <applet code="InsertItemExample" width=200 height=200> </applet> */ public class InsertItemExample extends Applet{ Choice language = null; public void init(){ //create choice or combobox language = new Choice(); //add items to the choice language.add("Java"); language.add("C++"); language.add("VB"); language.add("Perl"); //add choice or combobox add(language); /* * To insert an item at a specified index in a choice or combobox, use * void insert(String item, int index) method of AWT Choice class. * * This method behaves as below * * 1. Existing items will be shifted up by 1 * * 2. If there are no items in the list, the insert item will be * first in the list and selected by defaulted. * * 3.If the index is grater than number of items in a choice, the item * will be inserted at last position. * */ language.insert("PHP",2); } } |
Example Output
Add Comment