2011-01-03 2 views
1

J'ai trouvé ce qui suit solution for changing a JComboBox arrow's color:Changer de couleur d'arrière-plan JComboBox Flèche

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 

Comment faire exactement vous « paintIcon l'icône du contexte graphique de la BufferedImage »?

Répondre

1

Comme ceci:

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); 
     } 
    } 
Questions connexes