@sgold said:
Thanks for your replies, Chris. And thanks, Paul, for moving this topic to the correct forum section.
I’m using showMenu(null, 0, 0) to display the menu, and it seems to be displayed properly. However, something is causing the menu to disappear as soon as I release the LMB; I don’t know what or why. I want to menu to remain visible until a selection is made, or (perhaps) until I click outside the menu.
I’m testing on Windows 7. There are no submenus yet.
I tried putting a breakpoints in Menu.hideMenu() and Menu.onMouseLeftReleased(), and neither one was hit.
I wonder if my issue might have to do with the fact that I show the menu on an update instead of when LMB is pressed/released. Does showMenu make any assumptions about the state of the LMB?
Let me post an example that should work and check it against what you are doing to see if there is a difference. Out of curiosity, do SelectBox and ComboBox drop-downs display ok? They use menu’s for there drop-down lists.
EDIT: And yes… likely this would be the case (the update issue you mentioned).
[java]
private ButtonAdapter showMenu;
private Menu menu1, menu2, menu;
private void initTest() {
// Create button to display first menu
showMenu = new ButtonAdapter(screen, new Vector2f(20,20), new Vector2f(100,25)) {
@Override
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean isToggled) {
menu.showMenu(null, getAbsoluteX(), getAbsoluteY()-menu.getHeight());
}
};
showMenu.setText("Show Menu");
////////////////////////////
// Create a random submenu
////////////////////////////
menu1 = new Menu(screen, "Menu1", new Vector2f(50, 50), new Vector2f(100, 25), false) {
@Override
public void onMenuItemClicked(int index, Object value, boolean isToggled) {
}
};
menu1.addMenuItem("Create Color Selector", "0", null);
menu1.addMenuItem("Create new Dialog Box", "1", null);
menu1.addMenuItem("Create new Alert Box", "2", null);
menu1.addMenuItem("Enable/Disable Tool Tips", "ToolTips", null, true);
menu1.addMenuItem("Enable/Disable Audio", "Audio", null, true);
menu1.addMenuItem("Enable/Disable Custom Cursors", "Cursors", null, true);
menu1.addMenuItem("Enable/Disable Cursor Effects", "CursorEffects", null, true);
menu1.getMenuItem(4).setIsToggled(true);
menu1.getMenuItem(5).setIsToggled(true);
// Remove default fade effect
menu1.removeEffect(Effect.EffectEvent.Show);
///////////////////////////////////
// Create a second random submenu
///////////////////////////////////
menu2 = new Menu(screen, "Menu2", new Vector2f(50, 50), new Vector2f(100, 25), false) {
@Override
public void onMenuItemClicked(int index, Object value, boolean isToggled) {
}
};
menu2.addMenuItem("Enable/Disable Chat Filter", "ChatFilter", null, true);
menu2.addMenuItem("Enable/Disable Chat Send Button", "ChatSend", null, true);
menu2.addMenuItem("This is one.", "3", null);
// Add first menu as a submenu to this menuitem
menu2.addMenuItem("This is menu item 16 and longer.", "1", menu1);
menu2.getMenuItem(0).setIsToggled(true);
// Remove default fade effect
menu2.removeEffect(Effect.EffectEvent.Show);
////////////////////////
// Create primary menu
////////////////////////
menu = new Menu(screen, "Menu3", new Vector2f(50, 50), new Vector2f(100, 25), false) {
@Override
public void onMenuItemClicked(int index, Object value, boolean isToggled) {
}
};
menu.addMenuItem("This is a menu.", "1", null);
menu.addMenuItem("This is another.", "2", null);
menu.addMenuItem("This is one.", "3", null);
// Add second menu as a submenu to this menuitem
menu.addMenuItem("And another.", "4", menu2);
menu.addMenuItem("This is one", "5", null);
// Add first menu as a submenu to this menuitem as well
menu.addMenuItem("This is not.", "6", menu1);
menu.addMenuItem("This is 3 more.", "7", null);
menu.addMenuItem("And another.", "4", null);
menu.addMenuItem("This is one", "5", null);
menu.addMenuItem("This is not.", "6", null);
menu.setIsResizable(true);
menu.setResizeN(false);
menu.setResizeW(false);
menu.setResizeE(false);
menu.setResizeS(true);
// Remove default fade effect
menu.removeEffect(Effect.EffectEvent.Show);
screen.addElement(showMenu);
screen.addElement(menu1);
screen.addElement(menu2);
screen.addElement(menu);
}
[/java]
Drop this into your test project and call the method after creating the screen. Let me know if this works ok for you and then we’ll narrow down what was different.