Example usage for javax.swing DefaultFocusManager DefaultFocusManager

List of usage examples for javax.swing DefaultFocusManager DefaultFocusManager

Introduction

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

Prototype

public DefaultFocusManager() 

Source Link

Document

Constructs a DefaultFocusManager .

Usage

From source file:pipeline.parameter_cell_views.TextBox.java

public TextBox() {
    super();/*from   w ww.  j  av  a 2s  . c o m*/
    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));
}