ilex.gui.CheckBoxList Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of opendcs Show documentation
Show all versions of opendcs Show documentation
A collection of software for aggregatting and processing environmental data such as from NOAA GOES satellites.
The newest version!
package ilex.gui;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
/**
This displays a list containing checkboxes, one per line.
You must provide a ListModel containing CheckableItem objects.
*/
public class CheckBoxList
extends JList
{
private MyListModel model;
/** Constructor. */
public CheckBoxList()
{
super(new MyListModel());
model = (MyListModel)getModel();
setCellRenderer(new CheckListRenderer(this));
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
setBorder(new EmptyBorder(0,4,0,0));
addMouseListener(
new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
int index = locationToIndex(e.getPoint());
CheckableItem item =
(CheckableItem)getModel().getElementAt(index);
item.setSelected(! item.isSelected());
Rectangle rect = getCellBounds(index, index);
repaint(rect);
}
});
}
/**
* @return the list model containing the data.
*/
public DefaultListModel getDefaultModel() { return model; }
/**
* Checks or unchecks all elements in the list.
* @param checked the value that all checkboxes will be set to.
*/
public void selectAll(boolean checked)
{
int n = model.size();
for(int i=0; i