I am making a Java application where I show a couple of checkboxes with relevant item from a file. Based on the selection I have to modify the original file accordingly. I have done this part.
I now realized that there might be some information that the user wants to add extra. I therefore want to show a checkbox with a JTextField hooked to it. The idea that I am trying to use is that if the value of checkbox is true, the value of JTextField associated with it, is included in the file.
I want to do something like this:
checkBoxes[i] = new Checkbox(new JTextField("enter new member e.g private int newMember"), null, false);
then
if(checkBoxes[i]==true)
{
updatefile(file, checkBoxes[i]);
}
Where updateFile is a function that adds the value of checkBoxes[i] to file
Any idea on how should I work on this?
Just create the
JTextFieldseparately, there’s no need for them to be the same control.i.e.
If you want to enable/disable the textFields based on the selected state of the checkbox, do it using a listener – e.g. an
ActionListener: