I’m planning on combining JMenu and JCheckBoxMenuItem so I can have:
(1) a popup menu containing instances of this new component.
(2) this new component would have a check box on the left as well as being able to expand to the right and show other sub-menus (like a regular JMenu)
I had a couple questions:
First, am I reinventing the wheel? / Has this been done before?
Second, I’m trying to figure out how swing knows how to get the UI class for the extended Component class? (I see that JMenu for example has a String uiClassID member that’s somehow used for that, but it’s not the exact class name… I debugged it to a HashTable lookup in UIDefaults)
I think it would be confusing for the users to see a JMenu with a check box (if I understand correctly, you want to put this thing directly in a JMenuBar). I don’t think this has been done very often before, and there is a reason for that 🙂
The UI class that is used depends on the actual look and feel. See the subclasses of javax.swing.plaf.MenuItemUI
The full story about the Swing architecture is described here: http://java.sun.com/products/jfc/tsc/articles/architecture/
EDIT: if you want to put this in a popup menu, note that JPopupMenu is a JComponent, therefore you can put anything there, including normal JCheckBoxes. An example is here: http://www.javarichclient.com/do-more-with-jpopupmenu/