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?
 
for_yanConnect With a Mentor Commented:
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.