Example usage for javax.swing JComboBox requestFocusInWindow

List of usage examples for javax.swing JComboBox requestFocusInWindow

Introduction

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

Prototype

public boolean requestFocusInWindow() 

Source Link

Document

Requests that this Component gets the input focus.

Usage

From source file:Main.java

public static void main(String[] args) {
    JPanel gui = new JPanel(new GridLayout(0, 1, 5, 5));

    String[] speciesName = { "1", "2", "3" };
    String[][] breedName = { { "A", "P", "A" }, { "B", "P", "S" }, { "DDo", "A", "P" } };
    JComboBox<String> petSpecies = new JComboBox<>(speciesName);
    JComboBox<String> petBreed = new JComboBox<>();
    petSpecies.addItemListener(e -> {
        int ii = petSpecies.getSelectedIndex();
        ComboBoxModel cbm = new DefaultComboBoxModel(breedName[ii]);
        petBreed.setModel(cbm);/*from   w w w. j a v a2 s .  c o  m*/
        petBreed.requestFocusInWindow();
    });
    gui.add(petSpecies);
    gui.add(petBreed);

    JOptionPane.showMessageDialog(null, gui);
}

From source file:com.aw.swing.mvp.binding.component.BndSJTable.java

private JComboBox getJComboBox(ComboBoxModel comboBoxModel) {
    final JComboBox jComboBox = new JComboBox(comboBoxModel);
    jComboBox.addFocusListener(new CellEditableFocusListener());
    jComboBox.setRequestFocusEnabled(true);
    jComboBox.putClientProperty(CellEditorUtils.AW_CELL_EDITOR, Boolean.TRUE);
    jComboBox.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
    jComboBox.addAncestorListener(new AncestorListener() {
        public void ancestorAdded(AncestorEvent event) {
            jComboBox.requestFocusInWindow();
        }/*from ww  w .j  a  v a2 s .c om*/

        public void ancestorMoved(AncestorEvent event) {
        }

        public void ancestorRemoved(AncestorEvent event) {
        }
    });
    return jComboBox;
}