48 |
import javax.swing.JButton; |
import javax.swing.JButton; |
49 |
import javax.swing.JComboBox; |
import javax.swing.JComboBox; |
50 |
import javax.swing.JList; |
import javax.swing.JList; |
51 |
|
import javax.swing.SwingConstants; |
52 |
import javax.swing.SwingUtilities; |
import javax.swing.SwingUtilities; |
53 |
|
|
54 |
/** |
/** |
100 |
public MetalComboBoxButton(JComboBox cb, Icon i, boolean onlyIcon, |
public MetalComboBoxButton(JComboBox cb, Icon i, boolean onlyIcon, |
101 |
CellRendererPane pane, JList list) |
CellRendererPane pane, JList list) |
102 |
{ |
{ |
103 |
super(i); |
super(); |
104 |
comboBox = cb; |
comboBox = cb; |
105 |
comboIcon = i; |
comboIcon = i; |
106 |
iconOnly = onlyIcon; |
iconOnly = onlyIcon; |
201 |
*/ |
*/ |
202 |
public void paintComponent(Graphics g) |
public void paintComponent(Graphics g) |
203 |
{ |
{ |
204 |
|
super.paintComponent(g); |
205 |
if (iconOnly) |
if (iconOnly) |
206 |
{ |
{ |
207 |
Rectangle bounds = getBounds(); |
Rectangle bounds = getBounds(); |
233 |
else |
else |
234 |
g.setColor(MetalLookAndFeel.getControlDisabled()); |
g.setColor(MetalLookAndFeel.getControlDisabled()); |
235 |
FontMetrics fm = g.getFontMetrics(comboBox.getFont()); |
FontMetrics fm = g.getFontMetrics(comboBox.getFont()); |
236 |
// FIXME: the label may need truncating with '...' and the |
Rectangle textR = new Rectangle(); |
237 |
// alignment needs work |
text = SwingUtilities.layoutCompoundLabel(fm, text, null, |
238 |
g.drawString(text, insets.left + 5, fm.getAscent() + 4); |
SwingConstants.TOP, SwingConstants.LEFT, |
239 |
|
SwingConstants.CENTER, SwingConstants.RIGHT, |
240 |
|
innerArea, new Rectangle(), textR, 0); |
241 |
|
int yAdj = (textR.height - fm.getAscent()) / 2 + 1; |
242 |
|
g.setFont(comboBox.getFont()); |
243 |
|
g.drawString(text, textR.x, textR.y + textR.height - yAdj); |
244 |
} |
} |
245 |
} |
} |
246 |
} |
} |