Example usage for javax.swing JPanel requestFocusInWindow

List of usage examples for javax.swing JPanel requestFocusInWindow

Introduction

In this page you can find the example usage for javax.swing JPanel requestFocusInWindow.

Prototype

public boolean requestFocusInWindow() 

Source Link

Document

Requests that this Component gets the input focus.

Usage

From source file:com.net2plan.gui.GUINet2Plan.java

private static JPanel showAbout() {
    final JPanel aboutPanel = new JPanel();

    ImageIcon image = new ImageIcon(
            ImageUtils.readImageFromURL(GUINet2Plan.class.getResource("/resources/gui/logo.png")));
    JLabel label = new JLabel("", image, JLabel.CENTER);

    aboutPanel.setLayout(new MigLayout("insets 0 0 0 0", "[grow]", "[grow][grow]"));
    aboutPanel.add(label, "alignx center, aligny bottom, wrap");
    aboutPanel.add(new JLabel(ABOUT_TEXT), "alignx center, aligny top");
    aboutPanel.setFocusable(true);//from   w w w.  j a v a  2  s  . co m
    aboutPanel.requestFocusInWindow();

    aboutPanel.addKeyListener(new KeyAdapter() {
        private final int[] sequence = new int[] { KeyEvent.VK_UP, KeyEvent.VK_UP, KeyEvent.VK_DOWN,
                KeyEvent.VK_DOWN, KeyEvent.VK_LEFT, KeyEvent.VK_RIGHT, KeyEvent.VK_LEFT, KeyEvent.VK_RIGHT,
                KeyEvent.VK_A, KeyEvent.VK_B };
        private int currentButton = 0;

        @Override
        public void keyPressed(KeyEvent e) {
            int keyPressed = e.getKeyCode();

            if (keyPressed == sequence[currentButton]) {
                currentButton++;

                if (currentButton == sequence.length) {
                    ErrorHandling.setDebug(true);
                    aboutPanel.removeKeyListener(this);
                }
            } else {
                currentButton = 0;
            }
        }
    });

    return aboutPanel;
}