0

Am designing an application in java using netbeans, in which i need to call a "Save" function by clicking on the save item on the menu bar. Am able to call the function by having a button inside the main panel, but am not able to call the function when i click on the menu bar or any where else. How can this be done?

Gaurav
  • 55
  • 10

2 Answers2

1

First check if you have defined an actionPerformed() method for the menuitem from which you are trying to call the method. If not, then you can define an actionPerformed() method by right clicking on the menu item in the design frame and select "events>actionperformed" from the context menu. Also take care that the menu items objects should not be a static field.

Rakesh
  • 4,264
  • 4
  • 32
  • 58
  • I am able to call the function, but the function does not reflect any changes on the jPanel,i.e, the data in the text boxes or the combo boxes do not get affected. – Gaurav Jun 29 '11 at 11:54
  • Updating the data in the text boxes or the combo boxes has to done programatically. You have to write the code to update the contents of text boxes. If you can post the code, I could help you out. – Rakesh Jun 30 '11 at 05:05
1

Start with How to Use Menus, then see this example of How to Use Actions.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • I am able to call the function, but the function does not reflect any changes on the jPanel,i.e, the data in the text boxes or the combo boxes do not get affected.. – Gaurav Jun 29 '11 at 07:38
  • What function? What `JPanel`? What "data in the text boxes or the combo boxes?" – trashgod Jun 29 '11 at 11:23