The Artima Developer Community
Sponsored Link

Java Answers Forum
Java Menu

4 replies on 1 page. Most recent reply: Nov 29, 2004 6:43 PM by Richard Stegman

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
Richard Stegman

Posts: 3
Nickname: steg
Registered: Nov, 2004

Java Menu Posted: Nov 27, 2004 6:56 PM
Reply to this message Reply
Advertisement
I'm trying to figure out how to make a menu name on the menubar act like a menuitem. For example, rather than placing "Quit" as a menuitem under some menu, I'd like to place the menu "Quit" on the menubar and have the application exit when the user selects the "Quit" menu. Any help would be appreciated.


Singh M.

Posts: 154
Nickname: ms
Registered: Mar, 2002

Re: Java Menu Posted: Nov 28, 2004 4:41 AM
Reply to this message Reply
> I'm trying to figure out how to make a menu name on the
> menubar act like a menuitem. For example, rather than
> placing "Quit" as a menuitem under some menu, I'd like to
> place the menu "Quit" on the menubar and have the
> application exit when the user selects the "Quit" menu.
> Any help would be appreciated.

Did you try checking the Swing Tutorial available on Sun's site?

Richard Stegman

Posts: 3
Nickname: steg
Registered: Nov, 2004

Re: Java Menu Posted: Nov 28, 2004 1:32 PM
Reply to this message Reply
The Swing tutorial was my original reference. I've also looked at various texts from Sun and O'Reilly and invariably the discussion revolves around associating ActionListeners with JMenuItem objects and not JMenu objects. I've tried associating an ActionListener with a JMenu object to no avail. This seems strange as JMenu inherits from JMenuItem. Any thuoghts on what I'm missing?

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Java Menu Posted: Nov 29, 2004 1:18 AM
Reply to this message Reply
Add a Listener for keyTyped and MouseClicked:

jMenu1.addKeyListener(new java.awt.event.KeyAdapter() {
  public void keyTyped(java.awt.event.KeyEvent evt) {
    if (evt.getKeyCode() == evt.VK_ENTER) {
      doSomethingVeryImportant();
    }
  }
});
jMenu1.addMouseListener(new java.awt.event.MouseAdapter() {
  public void mouseClicked(java.awt.event.MouseEvent evt) {
    if (evt.getButton() == evt.BUTTON1) {
      doSomethingVeryImportant();
    }
  }
});

Richard Stegman

Posts: 3
Nickname: steg
Registered: Nov, 2004

Re: Java Menu Posted: Nov 29, 2004 6:43 PM
Reply to this message Reply
That's what I'm looking for. I obviously have much more to learn. Thanks for opening up another door.

Flat View: This topic has 4 replies on 1 page
Topic: Factory pattern Previous Topic   Next Topic Topic: problem with TEXT

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use