I’m using custom renderer on JList, but none of components rendered are accessible.
list.setCellRenderer(new ListCellRenderer() {
public Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected, boolean cellHasFocus) {
JCheckBox c = new JCheckBox();
JButton b = new JButton("My Button!");
JPanel p = new JPanel(new FlowLayout());
p.add(c);
p.add(b);
if (isSelected) {
p.setBackground(Color.LIGHT_GRAY);
}
return p;
}
});
Clicking on checkbox or button doesn’t do anything. I’ve also tried to add ActionListener to buttons, but it didn’t fire while clicked. The only thing that works is background color while selected item (see screenshot).
There is not even the “click animation” when I click the button.
alt text http://foto.darth.cz/pictures/2009-05-19_151057.png
So my question is, do I have to do something else to enable evens on rendered components?
Same as for Tables really. A renderer component is not actually a real component. It just like a template used to draw a fake component. Why don’t you try sticking your components in either a JScrollPane or make them into a one column JTable and implement the appropriate renderer/editors instead?