Example usage for javax.swing.plaf ComboBoxUI setPopupVisible

List of usage examples for javax.swing.plaf ComboBoxUI setPopupVisible

Introduction

In this page you can find the example usage for javax.swing.plaf ComboBoxUI setPopupVisible.

Prototype

public abstract void setPopupVisible(JComboBox<?> c, boolean v);

Source Link

Document

Set the visibility of the popup

Usage

From source file:Main.java

public void actionPerformed(ActionEvent e) {
    JComboBox jcb = (JComboBox) e.getSource();
    System.out.println("down action");
    ComboBoxUI ui = jcb.getUI();

    if (ui.isPopupVisible(jcb)) {
        int i = jcb.getSelectedIndex();
        if (i < jcb.getModel().getSize() - 1) {
            jcb.setSelectedIndex(i + 1);
            jcb.repaint();//www. j  ava2  s . c o m
        }
    } else {
        int nItems = jcb.getItemCount();

        ComboBoxEditor cbe = jcb.getEditor();

        String st; // Search text

        st = ((String) cbe.getItem()).toUpperCase();

        for (int i = 0; i < nItems; i++) {
            String item = ((String) jcb.getItemAt(i)).toUpperCase();

            if (item.startsWith(st)) {
                jcb.setSelectedIndex(i);
                break;
            }
        }

        ui.setPopupVisible(jcb, true);
    }
}