I am writing an application in Java and am using Netbeans IDE. I have set two JCheckBox
(chk1
and chk2
) and two JTextField
(jtextfield1
and jtextfield2
). I want that if I check chk1
, jtextfield2
will be set to uneditable and if I chk2
, jtextfield2
will be set to editable and vice versa.
How to use JCheckBox to make JTextField editable and vice versa?
With the code below, it works alright but if i check the chk2
all the text fields are set to uneditable.
private void ckDepoActionPerformed(java.awt.event.ActionEvent evt) {
if(ckDepo.isSelected()){
txtDeposit.setEditable(false);
}
else{
txtWithdraw.setEditable(true);
}
}
private void ckWithdrawActionPerformed(java.awt.event.ActionEvent evt) {
transact="withdraw";
if(ckWithdraw.isSelected()){
txtWithdraw.setEditable(false);
}
else{
txtDeposit.setEditable(true);
}
}