package jas2.util;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
/**
* A JPanel which has a checkbox embedded in its border. The contents of the panel
* are automatically insensitized when the checkbox is turned off.
*/
public class CheckBoxBorderPanel extends JPanel implements ItemListener
{
public CheckBoxBorderPanel(String title)
{
this(title,null,null);
}
public CheckBoxBorderPanel(String title, Border border)
{
this(title,border,null);
}
public CheckBoxBorderPanel(String title, LayoutManager layout)
{
this(title,null,layout);
}
public CheckBoxBorderPanel(String title, Border border, LayoutManager layout)
{
if (layout == null) layout = new FlowLayout();
if (border == null) border = BorderFactory.createEtchedBorder();
checkbox = new JCheckBox(title);
setLayout(layout);
setBorder(border);
add(checkbox,0);
checkbox.addItemListener(this);
}
public void doLayout()
{
setEnabled();
checkbox.setVisible(false);
super.doLayout();
checkbox.setVisible(true);
Dimension size = checkbox.getPreferredSize();
checkbox.setSize(size);
checkbox.setLocation(20,0);
}
public void itemStateChanged(ItemEvent e)
{
setEnabled();
}
private void setEnabled()
{
boolean set = checkbox.isSelected();
Component[] children = getComponents();
for (int i=0; i
Ads help maintain this website.