Results 1 to 3 of 3
  1. #1
    thorstenmz is offline Member
    Join Date
    Aug 2011
    Rep Power

    Default Connect MenuItem to status bar text

    Hi all,

    I have an application with a JMenuBar. To every MenuItem I added a MouseListener that will change the status bar text to show a description of the MenuItem.

    I'd like to have this behavior also when navigating the menu with the keyboard. I have no idea how to do it as a KeyListener won't provide the functionality needed.

    Your input would be valued.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power


    Try a FocusListener


    edit No, a FocusListener isn't triggered. You can use a ChangeListener on the lines of
    Java Code:
    ChangeListener changeListener = new ChangeListener() {
      public void stateChanged(ChangeEvent e) {
        if (((AbstractButton) e.getSource()).getModel().isArmed()) {
          setStatus("Now in " + ((AbstractButton) e.getSource()).getText());
        } else {
    Last edited by DarrylBurke; 08-07-2011 at 01:24 PM.

  3. #3
    thorstenmz is offline Member
    Join Date
    Aug 2011
    Rep Power


    Hey thanks a lot :-)

    Works like a charm for keyboard and mouse as well.

Similar Threads

  1. user enable MenuItem
    By Coiby in forum AWT / Swing
    Replies: 5
    Last Post: 02-26-2011, 06:03 AM
  2. Replies: 8
    Last Post: 12-17-2010, 03:43 AM
  3. textfield on a menuitem
    By cotarelo in forum AWT / Swing
    Replies: 1
    Last Post: 06-29-2010, 04:11 PM
  4. various actions in menuitem of popupmenu
    By Peggy in forum Java Applets
    Replies: 0
    Last Post: 12-11-2008, 11:50 AM
  5. MenuItem
    By Sarinam in forum New To Java
    Replies: 1
    Last Post: 07-15-2008, 10:30 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts