All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ilex.gui.CheckBoxList Maven / Gradle / Ivy

Go to download

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy