Here you can find the source of setDependency(final JCheckBox master, final JCheckBox slave)
Parameter | Description |
---|---|
master | master. |
slave | slave. |
public static void setDependency(final JCheckBox master, final JCheckBox slave)
//package com.java2s; // the terms of the GNU General Public License as published by the Free Software Foundation; import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class Main { /**//from w ww . j ava2 s .c om * Adds dependancy between two check boxes, so that the slave is enabled only when master is checked. * * @param master master. * @param slave slave. */ public static void setDependency(final JCheckBox master, final JCheckBox slave) { if (master == null || slave == null) return; slave.setEnabled(master.isSelected()); master.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { slave.setEnabled(master.isSelected()); } }); } }