FileDocCategorySizeDatePackage
EditableComboBox.javaAPI DocExample3323Thu Oct 24 20:14:22 BST 2002None

EditableComboBox

public class EditableComboBox extends JPanel

Fields Summary
private BookEntry[]
books
Map
bookMap
Constructors Summary
public EditableComboBox()


      
      // Build a mapping from book titles to their entries
      for (int i = 0 ; i < books.length; i++) {
        bookMap.put(books[i].getTitle(), books[i]);
      }

      setLayout(new BorderLayout()); 

      JComboBox bookCombo = new JComboBox(books);
      bookCombo.setEditable(true);
      bookCombo.setEditor(
        new ComboBoxEditorExample(bookMap, books[0]));
      bookCombo.setMaximumRowCount(4);
      bookCombo.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
              System.out.println("You chose " + ((JComboBox)e.getSource()).
                                                getSelectedItem()  + "!"); 
          }
      });
      bookCombo.setActionCommand("Hello");
      add(bookCombo, BorderLayout.CENTER);
    
Methods Summary
public static voidmain(java.lang.String[] s)

         JFrame frame = new JFrame("Combo Box Example");
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         frame.setContentPane(new EditableComboBox());
         frame.pack();
         frame.setVisible(true);