java - Grayed out textfield unless checkbox ticked -
how, using jtextfield
, can create program enable/disable textfield depending on whether or not checkbox ticked?
i have option which, if checked, needs take input. if not checked, i'd text field remain grayed out user unable enter text.
mchq08 did not give complete answer since code nothing if jcheckbox unchecked. don't need if block you'd need single line of code in item listener
checkbox.additemlistener(new itemlistener() { public void itemstatechanged(itemevent itemevent){ // line below line matters, enables/disables text field textfield.setenabled(itemevent.getstatechange() == itemevent.selected); } });
Comments
Post a Comment