我想创建一个自动完成程序,我正在使用JComboBox
。
现在我想删除JComboBox
中的向下箭头。如何删除箭头?
答案 0 :(得分:2)
JComboBox是复合JComponent,包含JButton和Icon,您可以通过setIcon(null)删除它或替换为另一个Icon
例如(如何使用简单步骤执行此操作,注意仅适用于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);