Example usage for javax.swing JTextField transferFocus

List of usage examples for javax.swing JTextField transferFocus

Introduction

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

Prototype

public void transferFocus() 

Source Link

Document

Transfers the focus to the next component, as though this Component were the focus owner.

Usage

From source file:Main.java

public static void main(String[] args) {
    JComboBox<String> comboBox = new JComboBox<>(new String[] { "A", "B", "C" });
    comboBox.setEditable(true);//  w ww . j a va  2 s  . co  m

    JTextField editorComponent = (JTextField) comboBox.getEditor().getEditorComponent();
    editorComponent.addActionListener(e -> {
        editorComponent.transferFocus();
    });

    JPanel panel = new JPanel(new FlowLayout());
    panel.add(new JLabel("Field 1"));
    panel.add(comboBox);
    panel.add(new JLabel("Field 2"));
    panel.add(new JTextField(10));
    panel.add(new JLabel("Field 3"));
    panel.add(new JTextField(10));

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocationRelativeTo(null);

    Container c = frame.getContentPane();
    c.setLayout(new BorderLayout());
    c.add(panel, BorderLayout.CENTER);
    frame.pack();
    frame.setVisible(true);
}