/** * Return a component that has been configured to display the specified * value. * * @param list The JList we're painting. * @param value The value returned by list.getModel().getElementAt(index). * @param index The cells index. * @param isSelected True if the specified cell was selected. * @param cellHasFocus True if the specified cell has the focus. * @return A component whose paint() method will render the specified value. */ @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { setText(value.toString()); setSelected(((CheckBoxList) list).getChecked(index)); setBackground(isSelected ? list.getSelectionBackground() : list .getBackground()); setForeground(isSelected ? list.getSelectionForeground() : list .getForeground()); setFocusPainted(false); return this; } }
setCellRenderer(new CheckBoxListRenderer());
setCellRenderer(new CheckBoxListRenderer());
/** * Return a component that has been configured to display the specified * value. * * @param list The JList we're painting. * @param value The value returned by list.getModel().getElementAt(index). * @param index The cells index. * @param isSelected True if the specified cell was selected. * @param cellHasFocus True if the specified cell has the focus. * @return A component whose paint() method will render the specified value. */ @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { setText(value.toString()); setSelected(((CheckBoxList) list).getChecked(index)); setBackground(isSelected ? list.getSelectionBackground() : list .getBackground()); setForeground(isSelected ? list.getSelectionForeground() : list .getForeground()); setFocusPainted(false); return this; } }