示例#1
0
 private static int getComboBoxBaselineResizeBehavior(JComboBox cb) {
   if (cb.isEditable()) {
     return getBaselineResizeBehavior(cb.getEditor().getEditorComponent());
   }
   ListCellRenderer renderer = cb.getRenderer();
   if (renderer == null) {
     if (brbListCellRenderer == null) {
       brbListCellRenderer = new DefaultListCellRenderer();
     }
     renderer = brbListCellRenderer;
   }
   Object value = null;
   Object prototypeValue = cb.getPrototypeDisplayValue();
   if (prototypeValue != null) {
     value = prototypeValue;
   } else if (cb.getModel().getSize() > 0) {
     value = cb.getModel().getElementAt(0);
   }
   if (value != null) {
     if (brbList == null) {
       brbList = new JList();
     }
     Component component = renderer.getListCellRendererComponent(brbList, value, -1, false, false);
     return getBaselineResizeBehavior(component);
   }
   return BRB_OTHER;
 }
 public void paintCurrentValue(Graphics g, Rectangle bounds, boolean hasFocus) {
   ListCellRenderer renderer = comboBox.getRenderer();
   Component c;
   Dimension d;
   c =
       renderer.getListCellRendererComponent(
           listBox, comboBox.getSelectedItem(), -1, false, false);
   c.setFont(comboBox.getFont());
   if (comboBox.isEnabled()) {
     c.setForeground(comboBox.getForeground());
     c.setBackground(comboBox.getBackground());
   } else {
     c.setForeground(UIManager.getColor("ComboBox.disabledForeground"));
     c.setBackground(UIManager.getColor("ComboBox.disabledBackground"));
   }
   d = c.getPreferredSize();
   currentValuePane.paintComponent(g, c, comboBox, bounds.x, bounds.y, bounds.width, d.height);
 }