void (final JCheckBox checkbox, final JComponent textfield) { checkbox.addActionListener(e -> { boolean selected = checkbox.isSelected(); textfield.setEnabled(selected); }); textfield.setEnabled(checkbox.isSelected()); }