2011-08-30 78 views
1

我想创建一个自动完成的程序,并且我正在使用JComboBox删除JComboBox中的向下箭头

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

+4

为什么呢?不发明ui小部件,用户会感到困惑! – kleopatra

+2

,因为我想要在Google中搜索时看起来就像在那里看到任何箭头,这正是我想要出现在我的JComboBox中。关于这件事的任何想法? – sack

回答

2

JComboBox是复合JComponent并包含JButtonIcon,您可以通过的setIcon(空)删除或另一个图标

例如(如何使用简单的步骤去做,注意有效期只是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);