Name: dbT83986 Date: 12/23/98 When the user pops up a JComboBox (hits the spacebar for Metal L&F), and then tries to navigate with the arrow keys, any ActionListeners for that CB will have their actionPerformed methods called, and there isn't any information in the given ActionEvent to show that this was only a navigation action rather than a selection (spacebar) action. Source: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class inc37498 extends JFrame { public inc37498() { try {UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); } catch (Exception e) {System.out.println("L&F error"); } String[] items = {"Item 1", "Item 2", "Item 3", "Item 4", "Item 5"}; JComboBox cb = new JComboBox(items); getContentPane().add(cb); cb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (e.getID() == ActionEvent.ACTION_PERFORMED) { System.out.println("CB action performed:" + e); } else { System.out.println("CB action:" + e); } } }); pack(); } public static void main(String[] args) { new inc37498().show(); } } (Review ID: 37498) ====================================================================== ###@###.### 10/12/04 18:24 GMT
|