I have to set the custom image in my dropdown for JComboBox. I was quite successful to remove it (by overriding getWidth()) but I am not able to replace arrow with my custom image. Here is my code snippet to get better idea. I don’t know where I am doing wrong but its showing some elevated portion at button section.
cmbYear = new JComboBox();
cmbYear.setUI(new BasicComboBoxUI(){
protected JButton createArrowButton() {
return new JButton() {
private static final long serialVersionUID = 1L;
public void setIcon(Icon defaultIcon) {
defaultIcon = new ImageIcon("images/dropdown_icon.png");
super.setIcon(defaultIcon);
}
// public int getWidth() {
// return 0;
// }
};
}
});
Please help me here. Thank you very much for you time and suggestions.
You could override getIcon instead. Cache icon as needed.