posted 12 years ago
i have create the new JList as below:-
JList AttachFileList = new JList(model);
AttachFileList.setCellRenderer(new CheckBoxListCellRenderer());
AttachFileList.setSelectionMode(DefaultListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
AttachFileList.setModel(model);
class CheckBoxListCellRenderer extends JComponent implements ListCellRenderer {
//private static final long serialVersionUID = 1L;
DefaultListCellRenderer defaultComp;
JCheckBox checkbox;
public CheckBoxListCellRenderer() {
setLayout(new BorderLayout());
defaultComp = new DefaultListCellRenderer();
/* defaultComp.setSelectionMode(DefaultListSelectionModel.MULTIPLE_INTERVAL_SELECTION);*/
checkbox = new JCheckBox();
checkbox.setBackground(getBackground());
checkbox.setSelected(false);
// checkbox.setSelected(true);
add(checkbox, BorderLayout.WEST);
add(defaultComp, BorderLayout.CENTER);
}
public Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected, boolean cellHasFocus) {
defaultComp.getListCellRendererComponent(list, value, index,isSelected, cellHasFocus);
checkbox.setSelected(isSelected);
return this;
}
}
problem is that when i clicked one of the item in the JList i can't deselect it my clicking it once again
please help me. . . i'll will help full to my project. . . . thanks in advance