Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.awt.event.KeyEvent;

import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.KeyStroke;

public class Main extends JPanel {

    public Main() {
        JComboBox cpmbo = new JComboBox();
        cpmbo.addItem("One");
        cpmbo.addItem("Two");
        cpmbo.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
                KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, KeyEvent.ALT_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK),
                "spacePopup");

        this.add(cpmbo);
    }

    public static void main(String[] args) {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add(new Main());
        f.pack();
        f.setVisible(true);
    }
}