swing - java netbeans disable another jFormattedTextField when the first one is empty -


I am using jFormattedTextField because it can be easily formatted because I want it instead of jTextField. I only allow input as a number.

Case:

I have two gerformed testfield forms, assuming they are txtA and txtb, txtB is disabled.

When txtA is empty, then TCTB will always be inactive. Otherwise, when txtA is not empty, TCTT will be enabled.

If I remove all input in TSTA, TCTB should be disabled.

I have put the code in the keyReleased event. Here's the code snippet:

  Private zeros txtAKeyReleased (java.awt.event.KeyEvent evt) {if (! (TxtA.getText). Equals (""))) {int Form = txtA.getText (). Length (); If (as> gt; 0) {txtB.setEnabled (true); } And {txtB.setEnabled (wrong); }} And {txtB.setText (null); TxtB.setEnabled (false); }}   

At a glance, it works but, it does not work perfectly.

When I type something in TCTA, then TCTB is enabled. Problem 1: But, if I remove all inputs in TSTA, then TCTB is still capable

Problem 2: Identifying TSTA as input of numbers only Then TCTB is enabled. But, when I typed the letter or place in TCTA, TSTT is still capable.

Surprisingly, when I try to do it in JetTapfield, it works perfectly (TCTB is disabled when Texta is empty).

What should I do to fix this?

I code in keyReleased event.

Do not use a KeyListener.

Instead you should use a DocumentListener . When a document is changed, it will set fire to an event. Read the section from the swing tutorial for more information and examples.

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -