6

So I have a JMenu with a few submenus inside. The names of those menus are set by getting the name of a 1 of 4 players. I added a MenuListener to the JMenu to update those names using

menu.setName(player.getName()); 

However, the name is changing but the update is not displaying in the menu. How do I get the menu to update it's display?

editMenu.addMenuListener(new MenuListener() {

       public void menuSelected(MenuEvent e) {
          updateMenu();       
       }

       public void menuDeselected(MenuEvent e) {
       }

       public void menuCanceled(MenuEvent e) {
       } 
});

and updateMenu method:

public void updateMenu()
{
    partOneMenu.setName(Participant1.getName());
    partTwoMenu.setName(Participant2.getName());
    partThreeMenu.setName(Participant3.getName());
    partFourMenu.setName(Participant4.getName());

    partOneMenu.revalidate();

    partTwoMenu.revalidate();
    partThreeMenu.revalidate();
    partFourMenu.revalidate();

    System.out.println(partOneMenu.getName());
}

The print statement is showing that the name has changed.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
John Powers
  • 267
  • 5
  • 13

1 Answers1

5

If I understand what exactly you want (a snapshot could have been useful), then you should use menu.setText("player1")

setName(string) is not for display, see here.

Community
  • 1
  • 1
yair
  • 8,945
  • 4
  • 31
  • 50