• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Getting the names of the subcomponents of a JMenu  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

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)
Metal
Nimbus
CDE/Motif
GTK+
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?

Regards,

George
 
Rancher
Posts: 2941
19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
George Kyrillos
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Example:


I thought that the getName() method would return "systemThemeMenuItem", so I can use it to set it selected or not...
 
Rob Camick
Rancher
Posts: 2941
19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!