I have created a JMenuItem and a JButton in a JForm.
Is there an easy way to connect them so that they perform the same action, using Netbeans IDE?
Thank you.
I have created a JMenuItem and a JButton in a JForm. Is there an
Share
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.
Use a
javax.swing.Actionto implement the logic (e.g. by extendingjavax.swing.AbstractAction) and then assign the action to the menu item and the button. Both have a constructor that takes an Action as the parameter.Enabling/Disable the action will then also enable/disable the button and the menu item.
See the Swing tutorial‘s chapter about using actions for more details