How do you set the selection character on a button

Say I have 3 buttons "Ok", "Cancel", and "Exit".  I want O, C, E respectively to be the hot character.  How do I set it?
Vanavah EdwardsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

for_yanCommented:
Simple example:
http://www.java2s.com/Tutorial/Java/0240__Swing/UsingMnemonics.htm

import java.awt.event.KeyEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
public class MnemonicButton {
  public static void main(String args[]) {
    JFrame frame = new JFrame("DefaultButton");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JButton button1 = new JButton("Text Button");
    button1.setMnemonic(KeyEvent.VK_B);
    frame.add(button1);
    frame.setSize(300, 200);
    frame.setVisible(true);
  }
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vanavah EdwardsAuthor Commented:
It works.  I am now getting an error that wants to shut down Eclipse  - Unhandled event loop exception, unable to create new native thread.
0
Vanavah EdwardsAuthor Commented:
I restarted Eclipse and I didn't get the error again.  I don't understand what happened but it only occured when I set the keyevent.  I will now close this session.  I have a buttongroup problem that I wlll now post.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.