// 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);