Q:

How to Change Default Inputs for JComboBox and JButton

How do I make the Enter key trigger a JComboBox or JButton in a GUI rather than having to hit the Space key? I have an assortment of text fields and check boxes with buttons and combo boxes in between. I'd like to avoid having to switch between hitting space and enter and rather only have to hit enter for all components.
package koning.personal.dungeonsanddragons;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class test {

JFrame window = new JFrame("testGUI");
JPanel windowPanel = new JPanel();

public static JLabel labelSize;
public static JComboBox<String> comboSize;

public static JLabel labelButton;
public static JButton buttonButton;

public test () {
    super();

    labelSize = new JLabel("Monster Size:");
    String[] sizeChoices = { "None", "Tiny", "Small", "Medium", "Large", "Huge", "Colossal"};
    comboSize = new JComboBox<String>(sizeChoices);
    comboSize.setToolTipText("The creature's size.");

    labelButton = new JLabel("Button:");
    buttonButton = new JButton();

    windowPanel.setLayout(new FlowLayout());
    windowPanel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    windowPanel.add(labelSize);
    windowPanel.add(comboSize);
    windowPanel.add(labelButton);
    windowPanel.add(buttonButton);
    windowPanel.setVisible(true);

    window.setSize(500, 500);
    window.setLayout(new FlowLayout());
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.setVisible(true);
    window.add(windowPanel);

    comboSize.addActionListener(handler);
    buttonButton.addActionListener(handler);
}

ActionHandler handler = new ActionHandler();
public class ActionHandler implements ActionListener {
    public void actionPerformed(ActionEvent eventFocus){
        if (eventFocus.getSource() == comboSize){
            buttonButton.requestFocusInWindow();
        }
        if (eventFocus.getSource() == buttonButton){
            comboSize.requestFocusInWindow();
        }
    }
}

@SuppressWarnings("unused")
public static void main(String[] args) {
    test GUITest = new test();
}

}

A:

You can add a KeyListener and execute doClick
JButton btn = new JButton();
    btn.addKeyListener(new KeyListener() {

        @Override
        public void keyTyped(KeyEvent e) {
            if(e.getKeyCode() == KeyEvent.VK_ENTER)
                btn.doClick();

        }

        @Override
        public void keyReleased(KeyEvent e) {
            // TODO Auto-generated method stub

        }

        @Override
        public void keyPressed(KeyEvent e) {
            // TODO Auto-generated method stub

        }
    });

