19 package org.sleuthkit.autopsy.guiutils;
21 import java.awt.BorderLayout;
22 import java.awt.Component;
23 import java.awt.event.MouseAdapter;
24 import java.awt.event.MouseEvent;
25 import javax.swing.Icon;
26 import javax.swing.JCheckBox;
27 import javax.swing.JLabel;
28 import javax.swing.JList;
29 import javax.swing.JPanel;
30 import javax.swing.ListCellRenderer;
31 import javax.swing.ListSelectionModel;
96 CellRenderer cellRenderer =
new CellRenderer();
98 setCellRenderer(cellRenderer);
99 addMouseListener(
new MouseAdapter() {
101 public void mousePressed(MouseEvent e) {
102 int index = locationToIndex(e.getPoint());
103 if (index != -1 && isEnabled()) {
110 setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
116 class CellRenderer
extends JPanel implements ListCellRenderer<CheckBoxJList.CheckboxListItem> {
118 private static final long serialVersionUID = 1L;
120 private final JCheckBox checkbox =
new JCheckBox();
121 private final JLabel label =
new JLabel();
124 setLayout(
new BorderLayout(2, 0));
125 add(checkbox, BorderLayout.WEST);
126 add(label, BorderLayout.CENTER);
130 public Component getListCellRendererComponent(
131 JList<? extends CheckBoxJList.CheckboxListItem> list,
CheckBoxJList.CheckboxListItem value,
int index,
132 boolean isSelected,
boolean cellHasFocus) {
134 setBackground(list.getBackground());
136 checkbox.setSelected(value.isChecked());
137 checkbox.setBackground(list.getBackground());
138 checkbox.setEnabled(list.isEnabled());
139 checkbox.setOpaque(list.isOpaque());
140 label.setText(value.getDisplayName());
141 label.setEnabled(list.isEnabled());
142 label.setOpaque(list.isOpaque());
143 label.setBackground(list.getBackground());
144 if (value.hasIcon()) {
145 label.setIcon(value.getIcon());
148 setOpaque(list.isOpaque());
149 setEnabled(list.isEnabled());
void setChecked(boolean checked)
static final long serialVersionUID