java.awt.Choice

The java.awt.Choice class implements a popup menu with a fixed position. (The java.awt.PopupMenu class is a popup menu with no fixed position. It pops up when the user clicks and holds the right mouse button.)

Choice menu

Creating a choice menu is a little more complex than creating the other user interface components you've seen. There's an extra step, adding the menu items to the menu. That is the five steps are

  1. Declare the Choice
  2. Allocate the Choice
  3. Add the menu items to the Choice
  4. Add the Choice to the layout
  5. Add an ItemListener to the Choice

For example

 public void init() {

    Choice ch;
    ch = new Choice();
    ch.addItem("1");
    ch.addItem("2");
    ch.addItem("3");
    ch.addItem("4");
    ch.addItem("5");
    add(ch);

  }   

Previous | Next | Top | Cafe au Lait

Copyright 1997 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified November 4, 1997