本文介绍了删除JComboBox中的向下箭头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个自动完成程序,我正在使用 JComboBox
。
I want to create an auto complete program and I am using JComboBox
for this.
现在我要删除 JComboBox
中的向下箭头。如何删除箭头?
Now I want to remove the down arrow in the JComboBox
. How to remove the arrow?
推荐答案
是复合并包含 ,您可以通过setIcon(null)删除它或替换它与另一个图标
JComboBox is compound JComponent and contains JButton with Icon, you can remove that by setIcon(null) or replace with another Icon
例如(如何通过简单步骤执行此操作,注意仅适用于金属外观
)
for example (how to do it with simple steps, NOTICE valid just for Metal Look and Feel
)
JComboBox coloredArrowsCombo = myComboBox;
BufferedImage coloredArrowsImage = null;
try {
coloredArrowsImage = ImageIO.read(AppVariables.class.getResource("resources/passed.png"));
} catch (IOException ex) {
Logger.getLogger(someClessName.class.getName()).log(Level.SEVERE, null, ex);
}
if (!(coloredArrowsImage == null)) {
Icon coloredArrowsIcon = new ImageIcon(coloredArrowsImage);
Component[] comp = coloredArrowsCombo.getComponents();
for (int i = 0; i < comp.length; i++) {
if (comp[i] instanceof MetalComboBoxButton) {
MetalComboBoxButton coloredArrowsButton = (MetalComboBoxButton) comp[i];
coloredArrowsButton.setComboIcon(coloredArrowsIcon);
break;
}
}
}
编辑:为了更好的输出你可以放在这里 coloredArrowsButton.setRolloverIcon(someIcon);
for better output you can put here coloredArrowsButton.setRolloverIcon(someIcon);
这篇关于删除JComboBox中的向下箭头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!