1

this is the event on window open

when the JForm Opens This Happens

I just want to make this the feature just like adding a question to stackoverflow in

editor and display simultaneously updated content below the editior

 private void formWindowOpened(java.awt.event.WindowEvent evt) {                                  

    Thread t1 = new Thread();
    t1.start();
}    

this is the main method

    public static void main(String args[]) {

    Thread t1 = new Thread(
            () -> {
                // DEMO is the Name of JForm
                DEMO d = new DEMO();
                // Text1 is the first jtextfeild
                String x = d.Text1.getText();

                if (x.isEmpty()) {
                    //ButtonAdd is the jbutton in JFrom
                    d.ButtonAdd.setEnabled(false);
                } else {
                // Text2 is the Second jtextfeild
                    d.Text2.setText(x);
                    d.ButtonAdd.setEnabled(true);
                }

            }
    );

    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new DEMO().setVisible(true);
        }
    });
}
Waleed Zia
  • 11
  • 2
  • 1
    1) You don't need a new Thread for this. You need a `DocumentListener`. Look at this [answer](https://stackoverflow.com/questions/44550511/add-a-character-or-a-string-when-enter-is-pressed-in-a-jtextpane/44550670#44550670) basically you disable your button when first show it, and listen for any key typed in the `JTextField`, if something is typed in, you enable the button. 2) `d.Text1.getText()` makes me think you're using `static` components which might give you more troubles than solutions. – Frakcool Sep 18 '19 at 17:02
  • See: https://stackoverflow.com/questions/29438072/unlock-jbutton-as-fields-have-text/29438641#29438641 it allows you to enable a button as text is added in 1 or more text fields. – camickr Sep 19 '19 at 01:28

1 Answers1

0

Disable ButtonAdd while initialization and add following Listener to d.Text1

new TextFieldChangeListener(tf)
     {
       public abtract void onChange(String oldText, String newText)
       {
         d.Text2.setText(newText);
         if(newText.isBlank())
         {
              d.ButtonAdd.setEnabled(false);
         }
         else
         {
              d.ButtonAdd.setEnabled(true);
         }        
       }
     };
Rizwan
  • 1
  • 3