-
Bug
-
Resolution: Unresolved
-
P5
-
1.4.0, 5.0
-
x86, sparc
-
solaris_8, windows_xp
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.
// 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.
- relates to
-
JDK-4958729 REGRESSION: MenuBar behaves incorrectly sometimes
-
- Closed
-