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

Loose old menu when you change menu bars

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.0
    • 1.0
    • client-libs
    • 1.0beta2
    • x86, sparc
    • solaris_2.4, windows_nt
    • Verified

      All platforms: Loose previous menu bar when you replace it with new menu bar. It
      looks like the garbage collection is a little too agressive?

      Steps to reproduce
      Compile and run the attached code
      Select File | New
      // the menu bar should change
      Select Edit | Copy
      // the menu bar should change back to File
      Select File
      // Note: the menu has disappeared

      /* Tests changing a menu bar */

      import java.awt.*;

      class ChangeMenu extends AppFrame
      {
          private MenuBar fileMenu;
          private MenuBar editMenu;

          public ChangeMenu(String name)
          {
             super(name);
          
             // set new MenuBar
             fileMenu = new MenuBar();
             fileMenu.add(new FileMenu("File"));
             setMenuBar(fileMenu);

             editMenu = new MenuBar();
             editMenu.add( new EditMenu("Edit") );

             resize(200, 200);

          }
          

          public boolean menuEvent(Event evt, Object obj)
          {

             String label = (String) obj;
             if (label.equals("New") )
             {
                remove(fileMenu);
                setMenuBar(editMenu);
                return true;
             }
             else if (label.equals("Copy") )
             {
                remove(editMenu);
                setMenuBar(fileMenu);
                return true;
             }
             else
                return super.menuEvent(evt, obj);
          }


          public static void main(String args[])
          {
             ChangeMenu x = new ChangeMenu("Change Menu Test");
             x.show();
          }
      }



      /* Main Menu bar
       *
       */

      import java.awt.MenuItem;
      import java.awt.Menu;

      public class FileMenu extends Menu
      {
          // standard menu item labels
          public final String EXIT = "Exit";
          public final String NEW = "New";
          public final String OPEN = "Open";


          public FileMenu(String menuName)
          {
             super(menuName);
             add(new MenuItem(NEW));
             add(new MenuItem(OPEN));
             addSeparator();
             add(new MenuItem(EXIT));

          }

      }

      class EditMenu extends Menu
      {
          public final String COPY = "Copy";
          
          public EditMenu(String menuName)
          {
             super(menuName);
             add(new MenuItem(COPY) );
             addSeparator();
          }
      }
      /* Generic Full Application Frame
       * %W% %G% %U%
       * @author Kevin A. Smith
       *
       * The class AppFrame provides an AWT Frame window for running
       * applications.
       *
       */

      import java.awt.Frame;
      import java.awt.Event;
      import java.awt.MenuItem;

      // Application Frame window
      class AppFrame extends Frame
      {
          // constructor needed to pass window title to class Frame
      /* public AppFrame()
          {
             super("Untitled");
          }

       */
          public AppFrame(String name)
          {
             // call java.awt.Frame(String) constructor
             super(name);
          }

          // needed to allow window close
          public boolean handleEvent(Event e)
          {
             // Window Destroy event
             if (e.id == Event.WINDOW_DESTROY)
                return appExit(0);
             
             // it's good form to let the super class look at any
             // unhandled events
             return super.handleEvent(e);

          } // end handleEvent()

          // Generic Action event handler
          public boolean action(Event evt, Object obj)
          {
             if(evt.target instanceof MenuItem)
                return menuEvent(evt, obj);
             else
                // it is good form to let the super class look at any
                // unhandled events.
                return super.action(evt, obj);

          } // end action()

          // Generic Menu event handler
          public boolean menuEvent(Event evt, Object obj)
          {
             String menuLabel = obj.toString();

             if( menuLabel.equals("Exit") )
             {
                // This menu item is the same as Close
                return appExit(0);
             }

             else
                // menu event handler did nothing with this event.
                // In a fully written application, you should never
                // get to this line.
                return false;

          } // end menuEvent()

          protected boolean appExit(int exitCode)
          {
             System.exit(exitCode);
             return true;
          }
      } // end class AppFrame

      The description field as copied from bug report 1227968 follows:

      95/11/12
      This bug was originated by Bob Jervis. The bug has been sent to Sami Shaio.

      [Bob Jervis]
      We are getting a SIGBUS error consistently when we load our debugger page
          and then switch to another page.
      =============================================================

            sshaiosunw Sami Shaio (Inactive)
            kasmithsunw Kevin Smith (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: