Replace Item Of AWT List Example
- /*
- Replace Item Of AWT List Example
- This java example shows how to replace an item of a AWT List
- using Java AWT List class.
- */
- import java.applet.Applet;
- import java.awt.List;
- /*
- <applet code="ReplaceItemExample" width=200 height=200>
- </applet>
- */
- public class ReplaceItemExample extends Applet{
- List list = null;
- public void init(){
- //create a list with 5 visible rows
- list = new List(5, true);
- //add items to a list
- list.add("One");
- list.add("Two");
- list.add("Three");
- list.add("Four");
- list.add("Five");
- list.add("Six");
- list.add("Seven");
- //add list
- add(list);
- /*
- * To replace an item from a list, use
- * void replaceItem(String newValue, int index)
- * method of AWT List class.
- */
- //this will replace "two" with "ten"
- list.replaceItem("Ten",1);
- }
- }
Example Output




