Example usage for javax.swing JComboBox showPopup

List of usage examples for javax.swing JComboBox showPopup

Introduction

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

Prototype

public void showPopup() 

Source Link

Document

Causes the combo box to display its popup window.

Usage

From source file:Main.java

public Main() {
    JComboBox jc = new JComboBox();
    jc.addItem("France");
    jc.addItem("Germany");
    jc.addItem("Italy");
    jc.addItem("Japan");
    jc.addItemListener(this);
    add(jc);//  w ww  . j  av  a 2  s  . co  m

    jc.showPopup();
}

From source file:Main.java

public void keyPressed(KeyEvent evt) {
    JComboBox cb = (JComboBox) evt.getSource();

    int curIx = cb.getSelectedIndex();

    char ch = evt.getKeyChar();

    JComboBox.KeySelectionManager ksm = cb.getKeySelectionManager();
    if (ksm != null) {
        int ix = ksm.selectionForKey(ch, cb.getModel());
        boolean noMatch = ix < 0;
        boolean uniqueItem = ix == curIx;

        if (noMatch || !uniqueItem) {
            cb.showPopup();
        }// ww w .  j  av a  2 s. c  o m
    }
}

From source file:Main.java

public void keyPressed(KeyEvent evt) {
    JComboBox cb = (JComboBox) evt.getSource();

    int curIx = cb.getSelectedIndex();

    char ch = evt.getKeyChar();

    JComboBox.KeySelectionManager ksm = cb.getKeySelectionManager();
    if (ksm != null) {
        // Determine if another item has the same prefix
        int ix = ksm.selectionForKey(ch, cb.getModel());
        boolean noMatch = ix < 0;
        boolean uniqueItem = ix == curIx;

        // Display menu if no matching items or the if the selection is not unique
        if (noMatch || !uniqueItem) {
            cb.showPopup();
        }/* ww w . ja va  2  s.  co  m*/
    }
}