How to include events in components in JList
I am using a personalized renderer in JList, but none of the provided components are available.
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 a check box or button does nothing. I also tried adding an ActionListener to the buttons, but it didn't fire when clicked. The only thing that works is the background color when the item is selected (see screenshot).
When I click the button, there is not even a click animation.
alt text http://foto.darth.cz/pictures/2009-05-19_151057.png
So my question is, do I need to do something else to enable evens in the displayed components?
a source to share
The same as for tables. The render component is not actually a real component. It's like a template used to create a fake component. Why don't you try glueing your components into a JScrollPane, or making them into a single JTable column, and implement the appropriate renderer / editors instead?
a source to share