T
Thomas Richter
Hi,
is there a known problem with custom renderers in JComboBoxes?
I've here the following problem:
Given a class derived from the swing JComboBox with a custom
renderer given as follows
class ColorComboBoxRenderer implements ListCellRenderer {
/* snip */
public Component getListCellRendererComponent(JList list,
Object value,int index,
boolean isSelected,
boolean cellHasFocus) {
ColorLabel label = (ColorLabel)value;
//
if (isSelected) {
label.setBackground(list.getSelectionBackground());
label.setForeground(list.getSelectionForeground());
} else {
label.setBackground(list.getBackground());
label.setForeground(list.getForeground());
}
// We should maybe render the selected item in a nicer way...
return label;
}
and a ColorLabel class that is directly derived from the JLabel, I get
no visible feedback at all if the user moves the pointer over the elements
of the ComboBox. However, I can make sure (by a couple of "println"'s) that
the code arrives at the right spot (above) and that the colors feed into
the label class are, as such, correct.
Any idea what's going on here? Is it impossible to change the background
color of a JLabel in a custom renderer of a JComboBox?
Greetings,
Thomas
is there a known problem with custom renderers in JComboBoxes?
I've here the following problem:
Given a class derived from the swing JComboBox with a custom
renderer given as follows
class ColorComboBoxRenderer implements ListCellRenderer {
/* snip */
public Component getListCellRendererComponent(JList list,
Object value,int index,
boolean isSelected,
boolean cellHasFocus) {
ColorLabel label = (ColorLabel)value;
//
if (isSelected) {
label.setBackground(list.getSelectionBackground());
label.setForeground(list.getSelectionForeground());
} else {
label.setBackground(list.getBackground());
label.setForeground(list.getForeground());
}
// We should maybe render the selected item in a nicer way...
return label;
}
and a ColorLabel class that is directly derived from the JLabel, I get
no visible feedback at all if the user moves the pointer over the elements
of the ComboBox. However, I can make sure (by a couple of "println"'s) that
the code arrives at the right spot (above) and that the colors feed into
the label class are, as such, correct.
Any idea what's going on here? Is it impossible to change the background
color of a JLabel in a custom renderer of a JComboBox?
Greetings,
Thomas