Custom Java ListCellRenderer - Can't click JCheckBox
Posted
by Spencer
on Stack Overflow
See other posts from Stack Overflow
or by Spencer
Published on 2010-05-14T09:28:02Z
Indexed on
2010/05/14
9:34 UTC
Read the original article
Hit count: 440
Made a custom ListCellRenderer:
import java.awt.Component;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;
/**
*
* @author Spencer
*/
public class TaskRenderer implements ListCellRenderer {
private Task task;
private JPanel panel = new JPanel();
private JCheckBox checkbox = new JCheckBox();
private JLabel label = new JLabel();
public TaskRenderer() {
panel.add(checkbox);
panel.add(label);
}
public Component getListCellRendererComponent(
JList list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus) {
task = (Task) value;
label.setText(task.getName());
return panel;
}
}
Have a JList with each cell in it rendered using the above class, but the checkboxes in the panels for each cell cannot be clicked. Thought it had to do with it not getting focus. Any ideas?
Thanks, Spencer
© Stack Overflow or respective owner