Esempio n. 1
0
 /**
  * Adds a popup menu.
  *
  * @param label the label
  * @param items the menu items
  * @param defaultItem the menu item initially selected
  */
 public void addChoice(String label, String[] items, String defaultItem) {
   String label2 = label;
   if (label2.indexOf('_') != -1) label2 = label2.replace('_', ' ');
   Label theLabel = makeLabel(label2);
   c.gridx = 0;
   c.gridy = y;
   c.anchor = GridBagConstraints.EAST;
   c.gridwidth = 1;
   if (choice == null) {
     choice = new Vector(4);
     defaultChoiceIndexes = new Vector(4);
     c.insets = getInsets(5, 0, 5, 0);
   } else c.insets = getInsets(0, 0, 5, 0);
   grid.setConstraints(theLabel, c);
   add(theLabel);
   Choice thisChoice = new Choice();
   thisChoice.addKeyListener(this);
   thisChoice.addItemListener(this);
   for (int i = 0; i < items.length; i++) thisChoice.addItem(items[i]);
   if (defaultItem != null) thisChoice.select(defaultItem);
   else thisChoice.select(0);
   c.gridx = 1;
   c.gridy = y;
   c.anchor = GridBagConstraints.WEST;
   grid.setConstraints(thisChoice, c);
   add(thisChoice);
   choice.addElement(thisChoice);
   int index = thisChoice.getSelectedIndex();
   defaultChoiceIndexes.addElement(new Integer(index));
   if (Recorder.record || macro) saveLabel(thisChoice, label);
   y++;
 }