Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4354929

Unfocused JButton receives ActionEvent

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.3.0
    • client-libs



      Name: jk109818 Date: 07/20/2000


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

      If we will run the following program, click on button, then click on list row
      and press 'Enter' the button will be pressed ! (Only if WindowsLookAndFeel is
      set.)

      import javax.swing.*;
      import java.awt.event.*;
      import java.awt.*;


      public class ListAndButton extends JFrame {

        static {
          try {
            UIManager.setLookAndFeel(
              "com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
          } catch (Exception exc) { System.err.println("Error loading L&F: " + exc); }
        }


        public ListAndButton()
        {
          Container cp = getContentPane();
          addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) { System.exit(0); }
          });
          setSize(400, 300);

          JList list = new JList(new String[] { "1", "2", "3" });
          list.addKeyListener(new KeyAdapter() {
            public void keyPressed(KeyEvent e)
            {
              if (e.getKeyCode()==KeyEvent.VK_ENTER) pr("List : Enter");
            }
          });
          cp.add(list);

          JButton but = new JButton();
          but.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) { pr("Button :
      actionPerformed"); }
          });
          cp.add(but, BorderLayout.EAST);
        }

        private static void pr (String s) { System.out.println(s); }

        public static void main(String[] args)
        {
          new ListAndButton().setVisible(true);
        }

      }
      (Review ID: 107412)
      ======================================================================

            mdavidsosunw Mark Davidson (Inactive)
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: