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

getModifiers() in class ActionEvent always returns 0

XMLWordPrintable

    • beta2
    • generic, x86, sparc
    • generic, solaris_2.5, windows_nt



      Name: mc57594 Date: 01/20/97


      For ActionEvents generated on Buttons or on TextFields
      the modifiers field is always 0. That is e.getModifiers()
      always returns 0. Testprogram:

      import java.awt.*;
      import java.awt.event.*;
      import java.util.*;

      public class EventTester extends Frame {

      final TextField tf = new TextField();
      final Button b = new Button("West");

      public EventTester() {
      ActionListener ah = new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      System.out.println(e.getModifiers());
      }
      };
      tf.addActionListener(ah);
      add(tf, "Center");
      b.addActionListener(ah);
      add(b, "West");
      pack();
      show();
      }

      public Dimension minimumSize() {
      return new Dimension(100,100);
      }

      public Dimension getPreferredSize() {
      return new Dimension(300,300);
      }

      public static void main(String[] arg) {
      new EventTester();
      }
      }
      ======================================================================

      Name: rmT116609 Date: 03/08/2001


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

      modifiers for actionPerformed event (SHIFT,ALT,CTRL) are not set for JMenuItems.

      run sample program below and press any of the modifier keys, then click the
      menu item. Notice that the modifier value is always 0.

      import javax.swing.*;
      import javax.swing.text.*;
      import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
      import java.awt.*;
      import java.awt.event.*;

      public class ButtonTest extends JFrame
      {

          public ButtonTest()
          {

              JMenuBar bar = new JMenuBar();
              JMenu menu = new JMenu("Menu");
              JMenuItem menuItem = new JMenuItem("item");
              menuItem.addActionListener(new ActionListener()
              {
                  public void actionPerformed(ActionEvent e)
                  {
                      System.err.println("modifiers for event "+e.getModifiers());
                  }
              });
              
              menu.add(menuItem);
              bar.add(menu);
              this.setJMenuBar(bar);
              
              setSize(200,150);
              setLocation(100,100);
              setVisible(true);
          }

          public static void main(String[] args)
          {
              ButtonTest inputTest1 = new ButtonTest();
          }
      }
      (Review ID: 118326)
      ======================================================================

            ehawkessunw Eric Hawkes (Inactive)
            mchamnessunw Mark Chamness (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: