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

Popup menus DO NOT WORK on windows95 if Frame has a menubar

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P1 P1
    • 1.1.6
    • 1.1, 1.1.1, 1.1.2, 1.1.3
    • client-libs
    • 1.1.6
    • x86
    • windows_95, windows_nt
    • Verified



        Name: mc57594 Date: 03/11/97


        If you add popup menus to the frame that has a menubar, the
        pop up menu doesn't work att all.

        1. It shows up without a title which I filed a separate bug
        report on.
        2. It doesn't have any text in it for menu items but occupies
        the entire width of the screen.

        THIS IS MAJOR and just a comment - it was working right on all
        beta releases and still works on Solaris

        import java.applet.*;
        import java.awt.*;
        import java.net.*;
         
        public class app extends Applet{
         
            public void start() {
            mFrame f = new mFrame();
            f.setSize(400,100);
            f.setVisible(true);
            }
        }
         
        class mFrame extends Frame {
            Menu p;
            public mFrame() {
                super();
                add("North",new Button("push me"));
         
            p = new PopupMenu("popup title");
            p.add(new MenuItem("item 1"));
            add((PopupMenu)p);
         
            MenuBar e = new MenuBar();
            e.add(new Menu("JDK1.1 stinks - write once , run everywhere - yeah right"));
            setMenuBar(e);
            }
         
            public boolean action(Event e, Object target) {
                ((PopupMenu)p).show((Component)this,20,60);
                return true;
            }
        }

        company - AT&T , email - ###@###.###
        ======================================================================
        import java.awt.Frame;

        import java.awt.MenuItem;
        import java.awt.Menu;
        import java.awt.MenuBar;
        import java.awt.PopupMenu;

        import java.awt.event.ActionEvent;
        import java.awt.event.ActionListener;
        import java.awt.event.MouseEvent;
        import java.awt.event.MouseListener;
        import java.awt.event.MouseMotionListener;
        import java.awt.event.WindowEvent;
        import java.awt.event.WindowListener;

        public class EditorFrame
        extends Frame
        implements ActionListener, MouseListener,
        MouseMotionListener, WindowListener
        {
        private Menu fileMenu;
        private MenuBar menuBar;
        private PopupMenu popupMenu;

        private String[] menu1Labels = new String[]
        { "Save", "Save As", "Quit" };
        private String[] popupLabels = new String[]
        { "Popup 1", "Popup 2", "Quit" };


        public EditorFrame()
        {
        super("Axiom Structured Editor");
        setBounds(10,10,500,600);

        menuBar = new MenuBar();

        fileMenu = createFileMenu();
        menuBar.add(fileMenu);
        setMenuBar(menuBar);

        popupMenu = createPopupMenu();
        add(popupMenu);

        //Need to listen for mouse events to activate popup menu
        addMouseListener(this);
        addMouseMotionListener(this);

        //Need to listen to respond to close event on the window
        addWindowListener(this);
        }

        public Menu createFileMenu()
        {
        MenuItem menuItem;
        Menu returnMenu;

        returnMenu = new Menu("File");
        for (int menu1Index = 0; menu1Index < menu1Labels.length; menu1Index++)
        {
        menuItem = new MenuItem(menu1Labels[menu1Index]);
        menuItem.addActionListener(this);
        returnMenu.add(menuItem);
        }

        return returnMenu;
        }

        public PopupMenu createPopupMenu()
        {
        MenuItem menuItem;
        PopupMenu returnMenu;

        returnMenu = new PopupMenu("Popups");
        for (int popupIndex = 0; popupIndex < popupLabels.length; popupIndex++)
        {
        menuItem = new MenuItem(popupLabels[popupIndex]);
        menuItem.addActionListener(this);
        returnMenu.add(menuItem);
        }

        return returnMenu;
        }

        //Intercept MouseMove to show popup menu
        public void processMouseEvent(MouseEvent event)
        {
        if (event.isPopupTrigger())
        popupMenu.show(this, event.getX(), event.getY());
        else super.processMouseEvent(event);
        }

        //Handle menu selection
        public void actionPerformed(ActionEvent event)
        {
        String command = event.getActionCommand();

        //I could do this in a oop and take strings from menu1Labels
        //but these will be replaced with actual response functions later
        //which will not correspond to a string

        if (command.equals("Save"))
        System.out.println("Save");
        if (command.equals("Save As"))
        System.out.println("Save As");

        if (command.equals("Popup 1"))
        System.out.println("Popup 1");
        if (command.equals("Popup 2"))
        System.out.println("Popup 2");

        if (command.equals("Quit"))
        System.exit(0);
        }

        //Close the Window then the close box is pressed
        public void windowClosing(WindowEvent event)
        {
        System.exit(0);
        }

        //These are needed to complete the MouseListener and MouseMotionListener
        //Interfaces

        public void mouseClicked(MouseEvent event) {;}
        public void mouseEntered(MouseEvent event) {;}
        public void mouseExited(MouseEvent event) {;}
        public void mousePressed(MouseEvent event) {;}
        public void mouseReleased(MouseEvent event) {;}
        public void mouseDragged(MouseEvent event) {;}
        public void mouseMoved(MouseEvent event) {;}

        //These are needed to complete the WindowListener Interface

        public void windowActivated(WindowEvent event) {;}
        public void windowClosed(WindowEvent event) {;}
        public void windowDeactivated(WindowEvent event) {;}
        public void windowDeiconified(WindowEvent event) {;}
        public void windowIconified(WindowEvent event) {;}
        public void windowOpened(WindowEvent event) {;}
        }


        /*
        In the above code, if line 40:
          setMenuBar(menuBar);
        is commented out or removed, the popup menu displays

        If left in, events are generated but the popup menu
        does not display the text.

        */
        =============================================================

        Compile the following code using javac, run using java. Press
        and release the right mouse button in the created window, observe
        how the popup menu is drawn. You can still select values in the
        popupMenu, but the text is not rendered and the width of the popupMenu
        is incorrect.

        No error messages or trace information is created.

        Source code demonstrating problem:
        /*
            Example code that demonstrates popup menu display failure in a Frame using JDK 1.1.2
            under Win32.

            If the frame does not have a menubar, the popup menu is displayed correctly (see the
            section labeled THE FIX).


            Note that even without the menubar, the popup menu does not display its label, even
            though the location where the popup menu is drawn is positioned with room enough for
            such a label.

            Test fails under both Win95 and NT 4.0 (w/SP3)
         */

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

        public class popup extends Frame implements ActionListener {

            MyPopupMenu popM = null;
            Menu fileMenu;

            public popup() {

             super("Popup window");

                popM = new MyPopupMenu("Test Popup Menu", this);
                add(popM);

             MenuBar mb = new MenuBar();
             fileMenu = new Menu("File");
             fileMenu.add(new MenuItem("New"));
             fileMenu.add(new MenuItem("Open..."));
             fileMenu.add(new MenuItem("Save"));
             fileMenu.add(new MenuItem("Save As..."));
             fileMenu.addSeparator();
             fileMenu.add(new MenuItem("Exit"));
             fileMenu.addActionListener(this);
             mb.add(fileMenu);

             //
             // THE FIX
             //
             // The following line is key - if you comment out the setMenuBar, the popup menu
             // is drawn correctly.
             //
             setMenuBar(mb);


             doLayout();
             addNotify();
             setSize(getInsets().left + getInsets().right + 462, getInsets().top + getInsets().bottom + 301);

                enableEvents(AWTEvent.MOUSE_EVENT_MASK | AWTEvent.WINDOW_EVENT_MASK);

             show();
            }

            protected void processWindowEvent(WindowEvent event)
            {
                if (event.getID() == WindowEvent.WINDOW_CLOSING) {
             setVisible(false); // hide the Frame
             dispose(); // tell windowing system to free resources
             System.exit(0); // exit
                }
            }

            protected void processMouseEvent(MouseEvent event)
            {
                if (event.isPopupTrigger() && popM != null) {
                    popM.show(event.getComponent(), event.getX(), event.getY());
                }
            }

            public void actionPerformed(ActionEvent event)
            {
        System.out.println("Received " + event.getActionCommand() + " command");

        if (event.getActionCommand().equals("Exit")) {
        setVisible(false);
        dispose();
        System.exit(0);
        }
            }

            public static void main(String args[]) {
             new popup();
            }

        }


        class MyPopupMenu extends PopupMenu
        {
            public MyPopupMenu(String label, ActionListener act)
            {
             super(label);

             MenuItem mi;

             mi = new MenuItem("Foo");
             mi.addActionListener(act);
             add(mi);

             mi = new MenuItem("Bar");
             mi.addActionListener(act);
             add(mi);
            }
        }

        I will note however, that for a project I was working on, this was a
        critical bug preventing us from moving to JDK 1.1 (we had emulation of
        popup menus in
        JDK1.0.2 but that emulation failed under 1.1).

        Dale Call
        Intel Corporation
        company - Intel Corporation , email - ###@###.###

        joon.oh@Eng 1997-09-19
        ==============================================================================
        import java.awt.*;
        import java.awt.event.*;
        /* Sample Java-source-code that demonstrates two
           bugs found in JDK 1.1.2 for MSDOS 95:
             - PopupMenus aren't shown properly under certain
               circumstances
             - The actionCommand of a MenuItem isn't assigned the item's
               label if using the constructor MenuItem(String, MenuShortcut)
        */
        public class MenuBug extends Frame implements ActionListener {
            PopupMenu _popup;
            public MenuBug() {

        //////////// PopupMenu looks quite strange ;-) /////////////////////////////
            // adding a PopupMenu and a MenuBar to a Frame makes the PopupMenu
            // look strange:
            // its height is normal, separators are shown correctly, and you
            // can trigger events, but there are no items visible, and the
            // menu's width covers the whole screen
            // workaround:
            // add a Panel,Canvas,etc to the Frame containing the MenuBar,
            // then add the PopupMenu to this Container.
                MenuBar mb = createMenuBar(this);
                setMenuBar(mb);
                _popup = createPopupMenu(this);
                add(_popup);
        ////////////////////////////////////////////////////////////////////////////
                enableEvents(AWTEvent.MOUSE_EVENT_MASK);
                setSize(300,200);
                show();
            }
            public void actionPerformed(ActionEvent e) {
                System.out.println(e.getActionCommand());
            }
            public void processMouseEvent(MouseEvent e) {
                if (e.isPopupTrigger()) {
                    _popup.show(e.getComponent(),e.getX(),e.getY());
                }
                super.processMouseEvent(e);
            }
            static public void main(String[] args) {
                new MenuBug();
            }
            PopupMenu createPopupMenu(ActionListener al) {
                PopupMenu pm = new PopupMenu("PopupMenu");
                MenuItem mi = new MenuItem("Click");
                mi.addActionListener(al);
                pm.add(mi);
                return pm;
            }
            MenuBar createMenuBar(ActionListener al) {
                MenuBar mb = new MenuBar();
                  Menu m = new Menu("Menu");
                    MenuItem mi;
        //////////// Behaviour of MenuItem-constructor differs from documentation
                    // this doesn't work properly:
                    mi = new MenuItem("Foo",new MenuShortcut('f'));
                    // should call setActionCommand with "Foo" implicitly,
                    // but doesn't seem to do so (notice the output 'null' at
                    // the command-line)
        /*
                    // this is working well:
                    mi = new MenuItem("Foo");
                    mi.setActionCommand("Foo"); // explicit call of setActionCommand
                    mi.setShortcut(new MenuShortcut('f'));
        */
        ////////////////////////////////////////////////////////////////////////////
                    mi.addActionListener(al);
                  m.add(mi);
                mb.add(m);
                return mb;
            }
        }


        company - Universitaet Wuerzburg , email - ###@###.###

              msomlosunw Mike Somlo (Inactive)
              mchamnessunw Mark Chamness (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: