JMenuItem displays weird name

137 Views Asked by At

I got my inv finally working! :D But, you know... now... it's dumb. I want it to say "Use Item 1" or whatever when I Right-click so I do this:

        if (actItemx == "Item 1") {
            popup.add(dropMenuItem + " " + actItemx); // should print "Use Item 1"
            popup.add(cancelMenuItem);
        }

Looks fine to me... but... when I compile, it's fine. When I run it, it's fine... but when I DO IT: waaaaht

I would have sworn that because it's displayed correctly in CMD that it would display correctly on JMenu... weird.

1

There are 1 best solutions below

2
On BEST ANSWER
popup.add(dropMenuItem + " " + actItemx);

That command is adding the toString() representaion of the dropMenuItem Swing component, plus a space, the the String value of actItemx.

I would guess you want:

popup.add(dropMenuItem.getText() + " " + actItemx);