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

1.4.2: Checkbox in popup menu does not work

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 6
    • 6
    • client-libs
    • b40
    • sparc
    • generic

      Tested this bug with checkboxes in popup menus in J2SE releases 1.3.1/1.4.1/1.4.2 (b14).

      Run the below test program and click on the test button, popup menu appears. If you click on the Checkbox, the item state should change and a message (print statement in itemStateChanged method) should appear on the screen. This does not happen. If you want to see how it works, click on the checkbox under File menu, you will see the message in stdout.

      However, this behaviour is not consistent. If you keep on clicking on the check box continously in popup menu, it will work (you will see the message) occasionally. I could not find any known bugs except for the one very old one 4045826.

      my_popup.java :
      ---------------

      import java.awt.*;
      import java.awt.event.*;
      import java.io.*;
      import java.awt.PopupMenu;
      import java.awt.CheckboxMenuItem;

      import java.awt.event.WindowAdapter;
      import java.awt.event.WindowEvent;

      class my_popup extends Frame implements ItemListener, ActionListener
      {
          private static my_popup m_instance;
          Button b;
          CheckboxMenuItem m_item;
          CheckboxMenuItem m_itemBar;
          PopupMenu p ;

          public void itemStateChanged(ItemEvent e)
          {
              System.out.println("Item changed: " + e);
          }

      public void actionPerformed(java.awt.event.ActionEvent event)
      {
              p.show(this, 100,100);
      }

          public my_popup() {
              setSize(400,400);

              m_instance = this;
              MenuBar mainMenuBar = new java.awt.MenuBar();
              Menu menu1 = new java.awt.Menu("File");

              MenuItem miRun = new java.awt.MenuItem("Run...");

              menu1.add(miRun);
              mainMenuBar.add(menu1);
              setMenuBar(mainMenuBar);
              b = new Button("test");
              b.addActionListener(this);
              p = new PopupMenu("test");
              add(p);
              m_item = new CheckboxMenuItem("check me");
              m_item.addItemListener(this);
              p.add(m_item);
              m_itemBar = new CheckboxMenuItem("check me in bar");
              m_itemBar.addItemListener(this);
              menu1.add(m_itemBar);
              b.setFont(new Font("Dialog", Font.PLAIN, 12));
              System.out.println("Font: " + b.getFont());
              add(b);
          }

          static public void main(String args[]) {
              my_popup pop = new my_popup();

              pop.addWindowListener(new WindowAdapter()
                  {
                      public void windowClosing(WindowEvent e)
                      {
                          System.exit(0);
                      }
                  });

              pop.show();

          }

      }

            vbaranovsunw Vyacheslav Baranov (Inactive)
            rverabel Raghu Verabelli (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: