2011-08-30 110 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);