• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Drop down menu

 
Gary Ba
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Does anyone know how to create a "drop down menu". I have created a Calculator and I want to add more feature to it like. file menu, exit, etc.
I used JPanel to create the screen. Please let me know,

Thank you,
Gary
 
subhash kumar
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://download.oracle.com/javase/tutorial/uiswing/components/menu.html
 
Gary Ba
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great Subhar! It looks like its what I need from the first glance.
Is this what they called Java Swing?

Gary
 
Gary Ba
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. I have another problem. I tried creating a Menu File -> exit. The File text showed up but when "File" is selected, there is no drop down for exit. Here is the added code I've created..



What am i missing?

Thanks,
Gary
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gary Ba wrote:What am i missing?

The initiative and staying power to systematically go through the tutorial linked by subhash (Subhar to you?).

That's not the way to use a JMenu.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gary Ba wrote:Great Subhar! (sic) . . .
Is this what they called Java Swing?

Gary
Yes, and that is what they call the forum where we usually discuss that sort of question, and where I shall move this thread.
 
Bobby Smallman
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You definitely need to go through basic Swing tutorials asap. A few things to get you started:
You do not need to go through all of that razzmataz(its a complex scientific term meaning excessive code which doesn't really make sense) to make your JMenuItem.

A simple: is sufficient.

Last tip before you go off and dig into Swing tutorials, order does matter. So do not add your JMenuItem to a JMenu after the JMenu has been added to a JMenuBar.
Good Luck to you in all your Java and Swing endeavors!
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bobby Smallman wrote:do not add your JMenuItem to a JMenu after the JMenu has been added to a JMenuBar.

How would that be a problem? Are you aware that menus are sometimes generated at runtime?
 
Gary Ba
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it!

I needed a JFrame in which the JMenuBar needed to be added.

Thanks for all the help.
Gary

Now I need to set up what JMenuItem should do.
 
Bobby Smallman
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:
Bobby Smallman wrote:do not add your JMenuItem to a JMenu after the JMenu has been added to a JMenuBar.

How would that be a problem? Are you aware that menus are sometimes generated at runtime?


I guess I was sleepy and didn't express myself accurately, I did not mean it as though it would not compile. I meant to say that your ordering of JMenuItems will be important when you have multiple items to place both visually and for readability.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic