本文介绍了如何更改 JComboBox 中的箭头样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我想在 JComboBox 中为箭头使用自定义图像,我该怎么做?
Let's say I want to use a custom image for the arrow in JComboBox, how can I do this?
我知道可以使用 synth xml 文件,甚至 UIManager.put(...),但我不知道如何使用.我此时想要做的就是将箭头图像更改为其他内容,以编程方式或什至只是覆盖它使用的图像.我究竟该怎么做?
I understand it's possible using the synth xml files, or maybe even UIManager.put(...), but I don't know how. All I want to do at this time is change the arrow image to something else, either programatically or even just overriding the image it uses. How exactly can I do this?
推荐答案
您可以覆盖 .BasicArrowButton
是一个方便的起点.
You can override createArrowButton()
in BasicComboBoxUI
. BasicArrowButton
is a convenient starting point.
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));
这篇关于如何更改 JComboBox 中的箭头样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!