Example usage for javax.swing JComboBox getUI

List of usage examples for javax.swing JComboBox getUI

Introduction

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

Prototype

public ComboBoxUI getUI() 

Source Link

Document

Returns the L&F object that renders this component.

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();//w  w w . j  a  va  2  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);
    }
}