JComboBox: setUI(ComboBoxUI ui) : JComboBox « javax.swing « Java by API






JComboBox: setUI(ComboBoxUI ui)

  
import java.awt.BorderLayout;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.plaf.ComboBoxUI;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicArrowButton;
import javax.swing.plaf.basic.BasicComboBoxUI;

public class MainClass {

  public static void main(final String args[]) {
    final String labels[] = { "A", "B", "C", "D", "E" };
    JFrame frame = new JFrame("Popup JComboBox");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JComboBox comboBox = new JComboBox(labels);
    comboBox.setUI((ComboBoxUI) MyComboBoxUI.createUI(comboBox));
    frame.add(comboBox, BorderLayout.NORTH);

    frame.setSize(300, 200);
    frame.setVisible(true);

  }

  static class MyComboBoxUI extends BasicComboBoxUI {
    public static ComponentUI createUI(JComponent c) {
      return new MyComboBoxUI();
    }

    protected JButton createArrowButton() {
      JButton button = new BasicArrowButton(BasicArrowButton.EAST);
      return button;
    }
  }
}

           
         
    
  








Related examples in the same category

1.implements JComboBox.KeySelectionManager
2.new JComboBox()
3.new JComboBox(ComboBoxModel aModel)
4.new JComboBox(Vector items)
5.JComboBox: addActionListener(ActionListener lis)
6.JComboBox: addItem(Object o)
7.JComboBox: addItemListener(ItemListener lis)
8.JComboBox: addPopupMenuListener(PopupMenuListener l)
9.JComboBox: getActionMap()
10.JComboBox: getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
11.JComboBox: getItemAt(int index)
12.JComboBox: getItemCount()
13.JComboBox: getKeySelectionManager()
14.JComboBox: getSelectedIndex()
15.JComboBox: getSelectedItem()
16.JComboBox: insertItemAt(Object anObject, int index)
17.JComboBox: isPopupVisible()
18.JComboBox: removeAllItems()
19.JComboBox: removeItemAt(int anIndex)
20.JComboBox: setEditor(ComboBoxEditor anEditor)
21.JComboBox: setKeySelectionManager(KeySelectionManager aManager)
22.JComboBox: setRenderer(ListCellRenderer aRenderer)
23.JComboBox: setEditable(boolean b)
24.JComboBox: setMaximumRowCount(int count)
25.JComboBox: setSelectedIndex(int anIndex)
26.JComboBox: setSelectedItem(Object anObject)