Results 1 to 3 of 3
  1. #1
    vsmilejay is offline Member
    Join Date
    Aug 2010
    Posts
    3
    Rep Power
    0

    Post Creating shortcutkey for jbutton

    I want to know how to create short key for jbutton without using mnemonics
    and i`ve used this code

    KeyboardFocusManager.getCurrentKeyboardFocusManage r()
    .addKeyEventDispatcher(new KeyEventDispatcher() {
    public boolean dispatchKeyEvent(KeyEvent e) {

    int c=e.getKeyCode();
    if(c==KeyEvent.VK_F2)
    JOptionPane.showMessageDialog(rootPane,"Selected);
    return false;

    }

    });

    }



    This code works,but if i press f2 for two time two MessageDialog Box are show .
    I want to know how to set f2 for display only one MessageDialog ...

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,244
    Rep Power
    19

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,457
    Rep Power
    25

    Default

    how to set f2 for display only one MessageDialog
    Have a boolean flag that you test and set that would control the display of the message.
    First time it's true and you set it false and display the message.
    The second time it's false and you just return.

Similar Threads

  1. JButton Help
    By ravjot28 in forum AWT / Swing
    Replies: 2
    Last Post: 01-17-2010, 01:07 PM
  2. how to give JButton a name when creating GridLayout
    By yasmin k in forum AWT / Swing
    Replies: 5
    Last Post: 11-03-2009, 11:16 PM
  3. Creating files stopped creating...
    By Dieter in forum Advanced Java
    Replies: 3
    Last Post: 09-25-2009, 11:45 PM
  4. Creating a JButton that does not show focus
    By Java Tip in forum javax.swing
    Replies: 0
    Last Post: 06-26-2008, 07:38 PM
  5. Help with JButton
    By geoffreybarwise in forum New To Java
    Replies: 4
    Last Post: 05-21-2008, 10:48 AM

Posting Permissions

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