I have a jCheckBox that, if the user checks it, creates a jTextArea under it, pushing everything and, if diselected, it disappears, pulling everything back. Something like this, but in Java.: https://youtu.be/gcNa0uqxytg?si=0u9VLzOvHX25c1E4&t=321
I already tried something like this, but nothing happens when I check/uncheck it.:
if(jCheckBox.isSelected()) {
jTextArea.setVisible(true);
} else {
jTextArea.setVisible(false);
}
Tried this too, but it causes error. error
Based on the error image you show your problem is not in the code you put up but rather in evt.getStateChange()
. Also you don't strictly need that if statement and could just change the whole method to a single line:
private void JCheckboxActionPerformed(...) {
txtField.setVisible(jCheckbox1.isSelected())
}
If that does not work then the problem might actually be in the layout and not the text field itself.
You should add the text field visible to your form and ones your happy how it looks you add
txtField.setVisible(false);
to the end of the constructor of the form.