I constructed a JMenu and would now like to add menu items. So what I have is:
- JMenu jm
- Action act
Now, for adding a menu item triggering action act: Does it make a difference if I use
jm.add(act);
or
jm.add(new JMenuItem(act));
?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
According to the documentation for JMenu.add(Action), it will create a new menu item for you, so they are essentially the same. So it’s ultimately a convenience method.
However, it also states:
And if we look at the source code for JMenu (retrieved from Google Code Search), this is what the
add(Action)method looks like:So no, there isn’t a big difference. But I’d still follow the documentation’s recommendation by manually making a control anyway.