Example usage for java.awt.event KeyEvent getComponent

List of usage examples for java.awt.event KeyEvent getComponent

Introduction

In this page you can find the example usage for java.awt.event KeyEvent getComponent.

Prototype

public Component getComponent() 

Source Link

Document

Returns the originator of the event.

Usage

From source file:pipeline.parameter_cell_views.TextBox.java

public TextBox() {
    super();//  ww  w. ja va2  s .com
    setLayout(new GridBagLayout());

    parameterName = new JLabel("");
    textField = new JTextArea(currentValue);
    textField.getDocument().addDocumentListener(new valueListener());
    // textField.setMinimumSize(new Dimension(150,40));
    textField.setLineWrap(true);
    textField.addMouseListener(this);

    textField.addKeyListener(new KeyAdapter() {
        // from http://www.java.net/node/650657
        @Override
        public void keyPressed(KeyEvent evt) {
            int iKey = evt.getKeyCode();
            JComponent component = (JTextArea) evt.getComponent();
            DefaultFocusManager focusManager = new DefaultFocusManager();
            if ((iKey == KeyEvent.VK_ENTER) ||
            // (iKey == KeyEvent.VK_DOWN) ||
            (iKey == KeyEvent.VK_PAGE_UP) || (iKey == KeyEvent.VK_PAGE_DOWN) || (iKey == KeyEvent.VK_TAB)) {
                evt.consume();
                focusManager.focusNextComponent(component);
            }
            // if (iKey == KeyEvent.VK_UP)
            // focusManager.focusPreviousComponent(component);
        }
    });

    c = new GridBagConstraints();
    c.fill = GridBagConstraints.BOTH;
    c.gridx = 0;
    c.gridheight = 2;
    c.weighty = 1.0;
    c.weightx = 1.0;
    c.gridwidth = 1;

    scrollPane = new JScrollPane(textField, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    add(scrollPane, c);
    scrollPane.setPreferredSize(new Dimension(1000, 500));
    scrollPane.setMinimumSize(new Dimension(10, 60));

    c.weighty = 0;
    add(parameterName, c);
    parameterNameAdded = true;
    parameterName.setMinimumSize(new Dimension(100, 30));
}