Hi,

You just use a DefaultComboBoxModel, but you need a custom ListCellRenderer:

For instance:

public class MyIconRenderer implements ListCellRenderer {

  // Most important method to override
  public Component getListCellRendererComponent(JList list, Object value, int
index,                                                  boolean isSelected, boolean 
cellHasFocus) {
        // LinkIcon is a custom-class that extends ImageIcon
        // and basically couples a name and description to an
        // ImageIcon (shouldn't be too hard)
        LinkIcon icon;
        if (value instanceof LinkIcon) {
          icon = (LinkIcon) value;
          if (icon.getIcon() != null) {
            this.setIcon(icon);
          }
        }
        setText(value.toString());
        return this;
  }
}

Since ListCellRenderer typically returns a Label, you can use both icon and
text.

Note: this will never compile, but it points you in the right direction (I hope)

Cheers,

Marijn






-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Thom
Burnett
Sent: Friday, May 10, 2002 1:58 PM
To: [EMAIL PROTECTED]
Subject: How do you put icon and text into a JComboBox?


Could someone ppoint me to a tutorial or example that results in a combo
box with both an icon and a text string being shown in a combo box?

--
Thom Burnett
_______________________________________________
Swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/swing



_______________________________________________
Swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/swing

Reply via email to