este es mi codigo:
Código:
esto es en el Jframe:import java.awt.Component; import java.util.HashMap; import java.util.Map; import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.ListCellRenderer; /** * * @author uSER */ public class RenderJCombobox extends JLabel implements ListCellRenderer { Map<Object, ImageIcon> elementos; ImageIcon imgnull=new ImageIcon(getClass().getResource("/pruebas/database_refresh.png")); public RenderJCombobox(){ elementos=new HashMap<>(); ImageIcon img1=new ImageIcon(this.getClass().getResource("/pruebas/database_refresh.png")); ImageIcon img2=new ImageIcon(this.getClass().getResource("/pruebas/user_add.png")); elementos.put("uno", img1); elementos.put("dos", img2); } @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { if(elementos.get(value)!=null){ setIcon(elementos.get(value)); setText(""+value); }else{ setIcon(imgnull); setText(""+value); } return this; } }
Código:
JComboBox combo=new JComboBox(); combo.addItem("uno"); combo.addItem("dos"); RenderJCombobox render = new RenderJCombobox(); combo.setRenderer(render);