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:

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");
    JButton button1 = new JButton("Text Button");
    frame.setSize(300, 200);

Open in new window

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.
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.
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.