1 19 20 package org.netbeans.modules.tasklist.core.checklist; 21 22 import java.awt.Component ; 23 import javax.swing.JCheckBox ; 24 import javax.swing.JList ; 25 import javax.swing.ListCellRenderer ; 26 import javax.swing.UIManager ; 27 import javax.swing.border.Border ; 28 import javax.swing.border.EmptyBorder ; 29 30 33 public class DefaultCheckListCellRenderer extends JCheckBox 34 implements ListCellRenderer { 35 36 private static final long serialVersionUID = 1; 37 38 private static Border noFocusBorder; 39 40 44 public DefaultCheckListCellRenderer() { 45 super(); 46 if (noFocusBorder == null) { 47 noFocusBorder = new EmptyBorder (1, 1, 1, 1); 48 } 49 setOpaque(true); 50 setBorder(noFocusBorder); 51 } 52 53 public Component getListCellRendererComponent(JList list, Object value, 54 int index, boolean isSelected, boolean cellHasFocus) { 55 setComponentOrientation(list.getComponentOrientation()); 56 if (isSelected) { 57 setBackground(list.getSelectionBackground()); 58 setForeground(list.getSelectionForeground()); 59 } 60 else { 61 setBackground(list.getBackground()); 62 setForeground(list.getForeground()); 63 } 64 65 setEnabled(list.isEnabled()); 66 setFont(list.getFont()); 67 setBorder((cellHasFocus) ? UIManager.getBorder("List.focusCellHighlightBorder") : noFocusBorder); 68 69 setText((value == null) ? "" : value.toString()); 70 setSelected(((CheckListModel) list.getModel()).isChecked(index)); 71 return this; 72 } 73 } 74 | Popular Tags |