• Post Reply Bookmark Topic Watch Topic
  • New Topic

How can I add JMenuBar

 
Raymond Self
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I am trying to add a JMenuBar to this program with just one dropdown to select one option but I am getting an error with the setJMenuBar(menuBar); line as it does not extend JFrame does anybody know how I would add a menu to this program another way, any help is appreciated thanks

 
Rob Camick
Ranch Hand
Posts: 2700
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
does anybody know how I would add a menu to this program another way


Somewhere in your code you must have logic like:



Well, that is where you create and add the menubar to the frame.
 
Raymond Self
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I have the code below in the main method but if I do a frame.add(menuBar); then it just shows a frame with nothing in the panel instead of the whole calculator in the panel

 
Rob Camick
Ranch Hand
Posts: 2700
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your initial question you said you are trying to use the frame.setJMenuBar(...) method, so why are you now trying to use the add(...) method?
 
Raymond Self
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my first time attempting a JMenuBar so have not much idea how to go about it. I have looked online but most tutorials create a separate class instead of implementing it on an existing JFrame, I do not know which way to do it that is why I am looking for some help
 
Rob Camick
Ranch Hand
Posts: 2700
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my first time attempting a JMenuBar so have not much idea how to go about it.


You use the setJMenuBar() method. You stated that in your first question.

I have looked online but most tutorials create a separate class instead of implementing it on an existing JFrame,


No idea what that means. Again somewhere in the code you will see frame.setJMenuBar(...). So once again if the tutorial is using that method, why are you attempting to use the add(...) method? Follow the tutorial example.

I suggest you read the JMenuBar API and follow the link to the Swing tutorial on "How to Use Menus" for a working example.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!