2011-01-03 20 views
1

は、私が見つかりました。solution for changing a JComboBox arrow's color変更JComboBoxの矢印の背景色

For JComboBox and Metal L&F 
-- iterate recursively over the components of the JComboBox and grab a reference 
    to the button of class javax.swing.plaf.metal.MetalComboBoxButton 
-- get the icon by getComboIcon() 
-- create a BufferedImage (type ARGB) the size of the icon 
-- paintIcon the icon to the Graphics context of the BufferedImage 
-- iterate over the pixels of the BufferedImage and change any non-zero pixels 
    (by getRGB) to the color you want (by setRGB). 
-- construct a new ImageIcon from the image 
-- set the new icon to the button by setComboIcon 

どのように正確にあなた「のBufferedImageのグラフィックスコンテキストにアイコンpaintIcon」か?このよう

答えて

1

:別の方法として

int componentCount = comboBox.getComponentCount(); 
    for (int i = 0; i < componentCount; i++) { 
     Component component = comboBox.getComponent(i); 
     if (component instanceof MetalComboBoxButton) { 
      MetalComboBoxButton metalComboBoxButton = 
       (MetalComboBoxButton) component; 
      Icon comboIcon = metalComboBoxButton.getComboIcon(); 
      BufferedImage bufferedImage = 
       new BufferedImage(
        comboIcon.getIconWidth(), 
        comboIcon.getIconHeight(), 
        BufferedImage.TYPE_INT_ARGB); 
      comboIcon.paintIcon(
       metalComboBoxButton, bufferedImage.getGraphics(), 0, 0); 
     } 
    } 
1

は、このexampleに示すように、ComboBoxUIBasicArrowButtonのカスタムインスタンスを使用することを検討してください。