假设我想在JComboBox中使用自定义图像作为箭头,我该怎么做?
我了解可以使用synth xml文件或者UIManager.put(...)实现,但我不知道具体如何操作。我现在只想将箭头图像更改为其他图像,要么通过编程方式,要么仅覆盖它所使用的图像。我该如何做到这一点?
假设我想在JComboBox中使用自定义图像作为箭头,我该怎么做?
我了解可以使用synth xml文件或者UIManager.put(...)实现,但我不知道具体如何操作。我现在只想将箭头图像更改为其他图像,要么通过编程方式,要么仅覆盖它所使用的图像。我该如何做到这一点?
您可以在BasicComboBoxUI
中覆盖createArrowButton()
。BasicArrowButton
是一个方便的起点。
class ColorArrowUI extends BasicComboBoxUI {
public static ComboBoxUI createUI(JComponent c) {
return new ColorArrowUI();
}
@Override protected JButton createArrowButton() {
return new BasicArrowButton(
BasicArrowButton.SOUTH,
Color.cyan, Color.magenta,
Color.yellow, Color.blue);
}
}
JComboBox combo = new JComboBox();
combo.setUI(ColorArrowUI.createUI(combo));