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

setHelpMenu() does not place menu in right-most position

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P5
    • Resolution: Unresolved
    • Affects Version/s: 1.4.0, 5.0
    • Fix Version/s: tbd
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • CPU:
      x86, sparc
    • OS:
      solaris_8, windows_xp

      Description

      As has been described in bugs 4073930 and 4007382, setHelpMenu() does not behave as one might expect on Windows platforms. In native Windows applications, the Help menu is the last one in the menu bar. It is expected that MenuBar.setHelpMenu() will cause the Menu argument to become the last Menu in the MenuBar. However, this is not the case. The following test demonstrates this:

      // test Menu.setHelpMenu()

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

      public class HelpMenu implements ActionListener {
          static MenuBar mb;
          static HelpMenu hm;
          static Button addMenu;
          static Button addHelp;
          public static void main(String[] args) {
              hm = new HelpMenu();
              Frame f = new Frame("HelpMenu");
              f.setSize(600, 200);
              mb = new MenuBar();

              mb.add(createNewMenu());
              mb.setHelpMenu(createNewHelpMenu());
              mb.add(createNewMenu());
              f.setMenuBar(mb);

              f.setLayout(new FlowLayout());

              addMenu = new Button("Add Menu");
              addMenu.addActionListener(hm);
              f.add(addMenu);

              addHelp = new Button("Set New Help Menu");
              addHelp.addActionListener(hm);
              f.add(addHelp);

              f.setVisible(true);
          }

          public void actionPerformed(ActionEvent e) {
              if (e.getSource() == addMenu) {
                  mb.add(createNewMenu());
              }
              else if (e.getSource() == addHelp) {
                  mb.setHelpMenu(createNewHelpMenu());
              }
          }

          private static int menuNum = 0;
          public static Menu createNewHelpMenu() {
              menuNum++;
              Menu helpMenu = new Menu("HelpMenu " + menuNum);
              helpMenu.add("Help Item " + menuNum);
              helpMenu.add("Help Item " + menuNum);
              return helpMenu;
          }
          public static Menu createNewMenu() {
              Menu menu = new Menu("Menu");
              menu.add("Item 1");
              menu.add("Item 2");
              return menu;
          }
      }

      This has been the behavior in the JDK since at least 1.1.8. The work around is to write your app such that the Help menu is the last one to be added to the MenuBar.

      Filed as part of 4958729.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              bchristi Brent Christian
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Imported:
                Indexed: