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

Win32 Only: Menubar can not be reused.

XMLWordPrintable

    • 1.1.5
    • x86
    • windows_95
    • Verified


      ingrid.yao@Eng 1997-08-13

      Oracle Menubar can not be reused on Win32:

        If a MenuBar is reused on win32, it grows in height to a size of one normal
        height x number Of top level submenus. Also, some of those top level submenus
        wont display their labels. click "replace menu" again, all submenu label will
        show vertical instead of horizontal. The menu system is fairly unusable at
        this point. (Reused means removing all items and then adding new items, which
        we have to do because the API doesn't support insertion at a specific point)

      Test case:
      ==========================

      import java.applet.*;
      import java.awt.*;
      import java.awt.event.*;
      public class b509300 extends Applet implements ActionListener
      {
          Button mButton;
          Frame mFrame;
          Menu mSubMenu1;
          Menu mSubMenu2;
          Menu mSubMenu3;
          Menu mSubMenu4;
          MenuBar mTopMenu;
          public b509300(Frame frame)
          {
              mFrame = frame;
          }
          public static void main(String argv[])
          {
              Frame frame = new Frame("MenuBar size problems...");
              Applet tmp = new b509300(frame);
              frame.add(tmp, "Center");
              frame.setSize(300, 300);
              frame.show();
              tmp.start();
          }
          public void start()
          {
      mButton = new Button("Replace Menus");
              mButton.addActionListener(this);
              add(mButton);
              add(new Label("Click several times to reproduce this bug;"));
      add(new Label("the MenuBar will resize to a weird height."));
      mSubMenu1 = new Menu("SubMenu1");
      mSubMenu2 = new Menu("SubMenu2");
      mSubMenu3 = new Menu("SubMenu3");
      mSubMenu4 = new Menu("SubMenu4");
      mTopMenu = new MenuBar();
              mTopMenu.add(mSubMenu1);
        mTopMenu.add(mSubMenu2);
      mTopMenu.add(mSubMenu3);
              mTopMenu.add(mSubMenu4);
      mFrame.setMenuBar(mTopMenu);
          }
          public void actionPerformed(ActionEvent event)
          {
      if ( event.getSource() == mButton )
              {
      // Remove all the menus, then add them back.
      mTopMenu.remove(mSubMenu1);
      mTopMenu.remove(mSubMenu2);
      mTopMenu.remove(mSubMenu3);
      mTopMenu.remove(mSubMenu4);
      mTopMenu.add(mSubMenu1);
      mTopMenu.add(mSubMenu2);
      mTopMenu.add(mSubMenu3);
      mTopMenu.add(mSubMenu4);
              }
          }
      }


      Test case 2
      ====================
      /*
      ** Reuse a MenuBar to show the effects on Windows.
      **
      ** Click on the Button, and the MenuBar (with four Menus) expands to four
      ** lines, with no Menus visible, but with one Menu per line. (Press and
      ** drag the mouse in the MenuBar to see the four Menus.)
      */
      import java.applet.*;
      import java.awt.*;
      import java.awt.event.*;
      import java.io.*;
       
      public class MBarReuse extends Applet
          implements ActionListener
      {
          Button mButton;
          Frame mFrame;
          MenuBar mTopMenu;
       
          public MBarReuse(Frame frame)
          {
              mFrame = frame;
          }
       
          public static void main(String argv[])
          {
              Frame frame = new Frame("MenuBar reuse problems...");
              Applet tmp = new MBarReuse(frame);
              frame.add("Center", tmp);
              frame.setSize(300, 300);
              frame.show();
              tmp.start();
          }
       
       
          public void start()
          {
      mButton = new Button("Reuse MenuBar");
      mButton.addActionListener(this);
      add(mButton);
       
              mTopMenu = buildMenu(null);
              mFrame.setMenuBar(mTopMenu);
          }
       
       
          public MenuBar buildMenu(MenuBar bar)
          {
              MenuItem mMItem;
              Menu mSubMenu;
              boolean reuse;
       
              if ( bar == null )
      {
      // First time
      bar = new MenuBar();
                  reuse = false;
      }
      else
      {
      // Reuse the bar
      //for ( int i = bar.getMenuCount() - 1; i >= 0; i-- )
      for ( int i = bar.getMenuCount() - 1; i >= 1; i-- )
      {
      bar.remove(i);
      }
                  reuse = true;
      }
       
      if ( !reuse )
      {
              mMItem = new MenuItem("Plain1");
              mSubMenu = new Menu("First");
              mSubMenu.add(mMItem);
      bar.add(mSubMenu);
      }
       
              mMItem = new MenuItem("Plain2");
              mSubMenu = new Menu("Second");
              mSubMenu.add(mMItem);
      bar.add(mSubMenu);
       
              mMItem = new MenuItem("Plain3");
              mSubMenu = new Menu("Third");
              mSubMenu.add(mMItem);
      bar.add(mSubMenu);
       
              mMItem = new MenuItem("Plain4");
              mSubMenu = new Menu("Fourth");
              mSubMenu.add(mMItem);
      bar.add(mSubMenu);
       
      return bar;
          }
       
       
          public void actionPerformed(ActionEvent event)
          {
      if ( event.getSource() == mButton )
      {
      buildMenu(mTopMenu);
      }
          }
      }

            duke J. Duke
            tyao Ting-Yun Ingrid Yao (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: