DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2005
    Posts
    32

    Talking activating mnemonic keys on my buttons

    Hi

    I have setup mnemonic keys on all my buttons and now want to try and get them to do something - at the moment this is just writing a string to the console, but eventually it will be calling another method.

    For example, one of my buttons has:

    startButton = new javax.swing.JButton();
    startButton.setBackground(buttonColour);
    startButton.setFont(new java.awt.Font("MS Sans Serif", 1, 16));
    startButton.setForeground(buttonFontColour);
    startButton.setMnemonic('s');
    startButton.setToolTipText("Start new search");
    startButton.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
    startButton.setText("START SEARCH");
    startButton.setPreferredSize(new java.awt.Dimension(160, 25));
    gamePanel.add(startButton);

    I have been looking this up for the past three hours and am now a bit lost!

    I have looked up the KeyListener and then tried using the keyTyped or the keyPressed method. I now see that perhaps I should alter the line startButton.setMnemonic('s'); to something like startButton.setMnemonic(KeyEvent.VK_S);

    I also want it to accept upper or lowercase.

    Can anyone help with this please?

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    The Mnemonic key stroke must be combined w. the ALT key.
    eschew obfuscation

  3. #3
    Join Date
    Jul 2005
    Posts
    32
    Hi

    So should I be using startButton.setMnemonic('s'); or should I change it to startButton.setMnemonic(KeyEvent.VK_S);

    and then implement the Keylistener or the ItemListener?

    Thank you

  4. #4
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    Use the KeyEvent.VK_<char> . The char version of this method is supposedly
    obsolete. Use Actionlistener, - a button with a mnemonic will perform as if you
    mouseclicked it.
    eschew obfuscation

  5. #5
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560

    Here is the code for image display

    I've zipped it.
    I have laid out some java source that might be useful here:

    http://home.no.net/sjalle/Library.html

    PS: you may want to remove the package directive on top.
    Attached Files
    Last edited by sjalle; 07-27-2005 at 06:20 AM.
    eschew obfuscation

Similar Threads

  1. Dynamic Buttons disappearing
    By spudmasher in forum ASP.NET
    Replies: 3
    Last Post: 07-03-2005, 11:59 PM
  2. Hot Keys for toolbar buttons
    By Sunil Menon in forum .NET
    Replies: 0
    Last Post: 07-01-2002, 02:46 AM
  3. get the array of keycodes for the keys that were pressed
    By Michael \(michka\) Kaplan in forum VB Classic
    Replies: 8
    Last Post: 06-07-2002, 09:23 PM
  4. Replies: 0
    Last Post: 07-18-2001, 05:11 PM
  5. Replies: 0
    Last Post: 07-18-2001, 05:11 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links