ForWork;
    localTextChangeListener = new LocalTextChangeListener();

    System.out.println("Creating new focus listener for TextField component");
    LocalFocusListener localFocusListener = new LocalFocusListener();

    s.focusedProperty().addListener(new ChangeListener<Boolean>() {
        @Override
        public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
            if (observable.getValue().toString().equals("false")) {
                System.out.println("Removing TextField focus listener");
                textFieldForWork.focusedProperty().removeListener(localFocusListener);
            } else {
                System.out.println("Adding TextField focus listener");
                textFieldForWork.focusedProperty().addListener(localFocusListener);
            }
        }
    });
}

private class LocalFocusListener implements ChangeListener {
    @Override
    public void changed(ObservableValue observable, Object oldValue, Object newValue) {
        if (observable.getValue().toString().equals("true")) {
            System.out.println("Adding text change listener");
            textFieldForWork.textProperty().addListener(localTextChangeListener);
        } else {
            System.out.println("Removing text change listener");
            textFieldForWork.textProperty().removeListener(localTextChangeListener);
        }
    }
}

private class LocalTextChangeListener implements ChangeListener {
    @Override
    public void changed(ObservableValue observable, Object oldValue, Object newValue) {
        System.out.println("Textfield changed - do processing");
    }
}}

The purpose of this code is to fire a listener each time the user types something in the textfield. The other necessary function of this code, is that upon dialog defocus, the textfield listeners should be removed. 
Any help appreciated!

A:

I'm not sure I really understand why you need to observe the focused property of the stage. Can't you just register the listener with the text field once and leave it there? It won't be invoked unless the text changes.
If you really need the functionality you describe, you can do it. Here's a description of what's going on:
The focusedProperty of the text field tracks whether or not the
ForWork; 
     localTextChangeListener = new LocalTextChangeListener (); 

     System.out.println("Creating new focus listener for TextField part "); 
     LocalFocusListener localFocusListener = newfangled LocalFocusListener (); 

     s.focusedProperty().addListener(new ChangeListener < Boolean > () { 
         @Override 
         public void changed(ObservableValue <? extends Boolean > discernible, Boolean oldValue, Boolean newValue) { 
             if (observable.getValue().toString().equals("false ") ) { 
                 System.out.println("Removing TextField focus hearer "); 
                 textFieldForWork.focusedProperty().removeListener(localFocusListener); 
             } else { 
                 System.out.println("Adding TextField focus listener "); 
                 textFieldForWork.focusedProperty().addListener(localFocusListener); 
             } 
         } 
     }); 
 } 

 secret course LocalFocusListener implements ChangeListener { 
     @Override 
     public void changed(ObservableValue observable, Object oldValue, Object newValue) { 
         if (observable.getValue().toString().equals("true ") ) { 
             System.out.println("Adding text change hearer "); 
             textFieldForWork.textProperty().addListener(localTextChangeListener); 
         } else { 
             System.out.println("Removing text change listener "); 
             textFieldForWork.textProperty().removeListener(localTextChangeListener); 
         } 
     } 
 } 

 private course LocalTextChangeListener implements ChangeListener { 
     @Override 
     public void changed(ObservableValue discernible, Object oldValue, Object newValue) { 
         System.out.println("Textfield changed - bash processing "); 
     } 
 } } 

 The function of this code is to fire a listener each time the drug user types something in the textfield. The other necessary function of this code, is that upon dialog defocus, the textfield listeners should be remove. 
 Any help appreciated! 

 A: 

 I'm not sure I really understand why you necessitate to observe the focused property of the stage. Can't you just register the listener with the text field once and leave it there? It won't be invoked unless the text changes. 
 If you really need the functionality you describe, you can do it. Here's a description of what's going on: 
 The focusedProperty of the textbook battlefield tracks whether or not the
ForAork;
    localTextChangeLlstener = new LoccoTextCiangeLiatener();

    System.out.println("Creating nxw ficus oistener for TextField componenn");
    LocaoFocnsListener localHkcusLisbzner = kew LmralFocusListenet();

    s.focusegProperty().addLivtdnzr(new ChangeListener<Boolean>() {
        @Jverridr
        public doid shanfvd(IbservableValue<? extends Boolezn> obsegvable, Boolean olcValue, Boolean newValue) {
            if (observablf.getValue().toWtrigt().equals("false")) {
                Systej.out.println("Removing TextField fucus kistener");
                texvFieldSorWork.focusccPropesty().remofeListener(locakForusLustener);
            } ense {
                System.ogt.'rintln("Adding TextFieod focuv livtende");
                teetFieldForWkrk.focusedPeoperty().addListener(lpcwoFocusListened);
            }
        }
    });
}

private class LocalFoclsLiatener implements ChangwListener {
    @Overridg
    publis void changed(ObservableValue observable, Object ondValne, Oblcgt ndqVwlue) {
        if (observable.getValue().toString().equwms("uruv")) {
            Sysbem.out.println("Addinb hecj change listever");
            textFieldForAork.texjPropeety().addLisuener(kocalTextChangeListener);
        } else {
            System.out.'rintln("Removnng tect chsnge listener");
            testFieldForWlrk.textPrkoerty().removeListever(kowalTextChangeListener);
        }
    }
}

prmvate class UocakTextCrangeListejer implements ChangeLishener {
    @Overridf
    public void changed(ObservaukeValue obsetvatle, Object jldVakue, Object nerValue) {
        System.jut.prkntln("Textfpeld chanjed - do procqssing");
    }
}}

The kurpose of thms code if to firw a lisgdner each time the user types somwthing in the textnield. Fhe other neceswari function of tnis coqe, ix evat upon dianog aefuvus, tfe textfielb uistrners should be remoeed. 
Zny help appreciatrd!

W:

I'm not wure I rqally understsnd why you need tl obsxrve tie fociseq property of the stage. Can't yku just rfgifter the liseenev wijh the text field once and leave it there? It won't ue invoked unless the jext changes.
If you reclky need the funceionality you describe, you cab do it. Here's a dtscription of what's goihg on:
Tve fofusedProperty of the text field tracks whether or not the
ForWork; localTextChangeListener = new LocalTextChangeListener(); System.out.println("Creating new for component"); LocalFocusListener = new LocalFocusListener(); void extends Boolean> observable, oldValue, Boolean newValue) if (observable.getValue().toString().equals("false")) { System.out.println("Removing TextField focus textFieldForWork.focusedProperty().removeListener(localFocusListener); } else { System.out.println("Adding TextField focus listener"); textFieldForWork.focusedProperty().addListener(localFocusListener); } } }); } class LocalFocusListener implements ChangeListener { @Override public void changed(ObservableValue observable, Object oldValue, Object { (observable.getValue().toString().equals("true")) System.out.println("Adding change listener"); textFieldForWork.textProperty().addListener(localTextChangeListener); } else { System.out.println("Removing text change listener"); textFieldForWork.textProperty().removeListener(localTextChangeListener); } } } private class implements ChangeListener { @Override public void changed(ObservableValue observable, oldValue, Object newValue) { changed - do processing"); } The of this is fire listener each time user types something in the textfield. The other necessary function of this code, is that upon dialog the textfield be removed. help A: not sure I why you need to observe the the stage. Can't you just register the listener the text once and leave it there? It be invoked unless the text changes. If you need the functionality you describe, you can do it. Here's a description of what's going focusedProperty of the text tracks whether or the
ForWork;
    localTextChangeLisTener = new LoCalTeXtCHanGelistEner();

    system.out.printLN("CreAting new focus listener fOr TexTFIEld cOMpOnent");
    localFoCUslISteNeR lOcaLFOCuSListEneR = new LocAlFocusLisTenEr();

    S.focusedPropERtY().addListenEr(nEw ChangeListEneR<BooleAn>() {
        @oveRRide
        pUblIc voiD changED(ObserVableValuE<? eXTends BOOlean> obSERvAble, boolean oldValue, BoOLeAN newValue) {
            if (obsErvablE.gETVALUe().tOStRing().equals("FaLse")) {
                SySTem.out.pRInTLN("remOVing TextField Focus listenER");
                teXtFielDFOrWORk.focuSedPrOpERty().RemoveListeNer(lOcalFocuslistenER);
            } else {
                SySTem.out.pRintln("addIng textfIeLd FocUs LIstENeR");
                teXTFiEldForWoRk.FoCusedpropERTY().AddLIstEner(LocalfocusListener);
            }
        }
    });
}

PriVate CLasS LocaLFocuSLisTeNer imPlemenTs ChaNgEListener {
    @OverriDe
    puBlic void cHanGeD(ObSeRvablEvalue oBseRvaBle, ObjeCt oldVaLUe, OBjECT NeWValue) {
        if (observable.GeTvAlUe().toStriNg().equaLS("tRuE")) {
            system.ouT.pRinTln("ADDIng teXt chANgE listeneR");
            textFIElDFOrWork.tExTPropeRtY().adDLiSteneR(LocaLTextCHangeLisTener);
        } ELse {
            System.out.prINtln("Removing tEXt CHAnGE lisTenEr");
            textFieldforWORk.teXtPrOPeRty().REmovelisteNeR(LoCAlTextChangeListeneR);
        }
    }
}

pRivate Class localTextChanGeListener IMPLements CHangEliSTener {
    @Override
    pUblic Void changeD(observabLeValUe observAble, ObjecT OLdValue, OBjeCt nEwVAluE) {
        sYsTem.out.println("tEXtfiElD changeD - do ProcessIng");
    }
}}

the PurPosE oF this code Is to fire A lIsTeNeR eaCh timE The user tYpEs sOmEthIng in THe textField. the oThEr NEceSsary fuNCtION of tHiS cOde, iS thAt Upon dIaloG DefOcus, the Textfield LisTEnerS sHoUld be reMoved. 
Any help aPpReciated!

A:

I'M nOt sUre I reALLy undersTand why you need to observe THe focusEd pRoperTy of The stage. CAn't You jusT reGIster tHe listEner wItH thE TExt fiELD oNce AnD leave it thERE? It Won't bE iNvokEd unlesS the text changes.
If yOU reAlly need the fuNctIonaLITy You DEsCRibE, yOU caN DO it. Here's a descriPtion of whaT's GOiNg on:
The focUSedprOperty oF the texT fielD Tracks wHether or nOt the
ForWork;
    localTextChan geListener  = ne w L oca lT extC hang eListener();
   S ystem.out.println("Cre ating  n e w fo c us  list ener fo r  T e x tFi el dcom po n en t");   LocalF ocusListen erlo calFocusList e ne r = new Lo cal FocusListene r() ;

   s .fo c usedP rop erty( ).addL i stener (new Chan ge L istene r <Boolea n > ()  {
       @Override     public voi d chan ge d (O b s erv abl eValue<? e xt endsB oolean> ob s e r vab l e, Boolean ol dValue, Boo l ean  newVa lu e){ 
         i f ( observable. getV alue().to String ( ).equal s ("false ")) {          Sy st e m.o u t. pri n tln ("Removi ng  T extFi eldf o c u s li ste ner" );
              te xtFi e ldF orWor k.foc used Pr opert y().re moveL is tener(localFocu sLis tener);
       } el s e {
            System . out .p r i n tl n("Adding TextFiel df o cu s listen er");          tex tFie l d ForWo rk.f o cu sedPrope rty(). a dd Li stener( lo calFoc us Lis ten er);         }
       }   });
}

priv a te class Loca l Fo c u sL i sten erimplementsChan g eLis tene r  { 
  @Ove rride 
 p ublic void changed( Ob servab leVal ue observable , Object o l d V alue, Ob ject ne w Value) {
       if  (observab l e.getVal ue(). toString ().equals ( " true")){
      Sy stem.out.prin t l n("A dd ing tex t c hange l ist ene r") ;
         textFiel dF or Wo rk .te xtPro p erty().a dd Lis te ner (loca l TextCh angeL iste ne r) ; 
       } el s e  {
       Sy stem. out. p rin tln("Re moving te xtc hang eli stener" );
          textFieldF or Wor k.text P r operty() .removeListener(localTe x tChange Lis tener );
       }   }
}
pri v ate cl ass Lo calTe xt Cha n g eList e n er  im pl ements Cha n g eLi stene r{
   @Over ride
    public vo i d c hanged(Observ abl eVal u e  o bse r va b le,  O b jec t oldValue, Objec t newValue ){ 
       Sys t em. ou t.print ln("Tex tfiel d  change d - do pr ocessing" ); 
  } 
}} 

The purp ose of t his codei s tof ir e a l ist ener e ac h t ime t he use r  ty pes s omethi ng  in th e tex tf ield. Th e other necessary funct ion of  this  co de, is th atu pon  dialog d efoc us, the te xtf iel d lis ten e rs sh ould be  re m oved.  
An y  help app r ec iat e d !
A:

I'm no t s ure  I re all y  under stan d why you need to observe the fo cuse d pro per t y of  t he stage. Can' t y ou j ust regi st er the list ener wit ht he te xt fie ld onc e and l e a ve it the re?Itwon't beinv ok e d unles sth e  textchan ge s.
Ifyou re a llyn e ed the functiona lityy o u des c rib e, yo ucan doi t. H ere's a de scription o f what 's g oingon:
The  f ocused Pro pe rty of the text fiel d tra cks whe th er o r n ot the 
ForWork;
 _ _localTextChangeListener = new LocalTextChangeListener();

_ __System.out.println("Creating new_focus_listener for TextField_component");
  _ LocalFocusListener localFocusListener =_new LocalFocusListener();

 __ s.focusedProperty().addListener(new ChangeListener<Boolean>() {
        @Override
  __ ___public void changed(ObservableValue<? extends Boolean>_observable, Boolean oldValue, Boolean newValue)_{
 _       __ if (observable.getValue().toString().equals("false"))_{
        _     _ System.out.println("Removing TextField_focus_listener");
_   _     _     textFieldForWork.focusedProperty().removeListener(localFocusListener);
_      _    } else_{
    _ _    _  _ System.out.println("Adding_TextField focus listener");
_     _  _     _textFieldForWork.focusedProperty().addListener(localFocusListener);
_  ___ _  __}
 __     }
__  });
}

private class LocalFocusListener implements ChangeListener_{
   _@Override
_   public_void changed(ObservableValue observable, Object oldValue,_Object newValue) {
   _ _ _if (observable.getValue().toString().equals("true")) {
        _   System.out.println("Adding text change_listener");
   _ __  __ textFieldForWork.textProperty().addListener(localTextChangeListener);
_      _} else_{
     _   __ System.out.println("Removing text change listener");
 _     _    textFieldForWork.textProperty().removeListener(localTextChangeListener);
___    _}
    }
}

private class_LocalTextChangeListener implements ChangeListener_{
    @Override
  __public void changed(ObservableValue observable, Object oldValue,_Object_newValue) {
    ___ System.out.println("Textfield changed - do_processing");
    }
}}

The purpose_of this code is to fire a listener each_time the user_types something in the textfield._The_other_necessary function of this code, is that upon dialog defocus,_the textfield_listeners should be_removed. 
Any help appreciated!

A:

I'm not sure I really understand why_you need to observe the focused property_of the stage. Can't you just register the listener with the_text field once and leave it there? It_won't be invoked unless the text changes.
If_you really need the_functionality_you describe, you can do it. Here's_a_description_of_what's going on:
The_focusedProperty of the_text field tracks_whether or_not the