删除JComboBox中的向下箭头

我想创建一个自动完成程序,我正在使用JComboBox

现在我想删除JComboBox中的向下箭头。 如何删除箭头?

JComboBox是复合JComponent并包含带有Icon的 JButton ,您可以通过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);