Forums Register Login
Getting the names of the subcomponents of a JMenu

I am trying to get the names of the subcomponents of a JMenu, I am working in Linux.

my code is this:

This gets me the text of each JCheckBoxMenuItem. It works.

There are 14 JCheckBoxMenuItems in the JMenu "lookAndFeelMenu"

4 of them (the ones available on my system)
are created like this:

If I try to get the name, by invoking "item.getName()" it returns null for all the hardcoded JCheckBoxMenuItems except the 4 above
Any info please?


Swing components don't have a name property unless you specifically invoke the setName(...) method on the component.

I would suggest you just use the getText() method.

I thought that the getName() method would return "systemThemeMenuItem", so I can use it to set it selected or not...
The menu item will be selected when you click on it when the menu popup is displayed.

If you want to manually select the menu item, then you need a reference to the menu item.

I really don't understand your question because if you try to use the getName() method that means you have a reference to the menu item so you can just select it.
We've gotta get close enough to that helmet to pull the choke on it's engine and flood his mind! Or, we could just read this tiny ad:
ScroogeXHTML 7.1 - RTF to HTML5 / XHTML converter

This thread has been viewed 238 times.

All times above are in ranch (not your local) time.
The current ranch time is
Feb 19, 2018 12:55:55.