0
내가 시도한 것은 JList와 확인란입니다. 여러 항목을 선택할 수 없습니다. 그렇게하면 이미 선택된 항목의 선택이 취소됩니다. 여기서 내가 놓친 것은 무엇입니까?JCheckBox가있는 JList
JList recipientsList = new JList(
new RecipientWrapper[] { new RecipientWrapper("apple"), new RecipientWrapper("orange"),
new RecipientWrapper("mango"), new RecipientWrapper("paw paw"), new RecipientWrapper("banana") });
recipientsList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
recipientsList.setCellRenderer(new CheckboxListRenderer());
class CheckboxListRenderer implements ListCellRenderer<RecipientWrapper>
{
private static final long serialVersionUID = 1L;
private JCheckBox checkBox;
@Override
public Component getListCellRendererComponent(JList list,RecipientWrapper value, int index, boolean isSelected,
boolean cellHasFocus)
{
Component c = null;
if(value != null)
{
getCheckBox().setText(value.toString());
checkBox.setSelected(isSelected);
value.setSelected(isSelected);
c = checkBox;
}
else
{
c = new JLabel();
}
return c;
}
private JCheckBox getCheckBox()
{
if(checkBox == null)
{
checkBox = new JCheckBox();
}
return checkBox;
}
}
checkBox.setSelected (isSelected); 잘못된 부분입니다 .. 그것은 checkBox.setSelected (value.isSelected()) 여야합니다; MouseListener로 JList를 다시 칠해야한다. – Brunthavan