Note that there are some explanatory texts on larger screens.

plurals
  1. POUndo behavior on textField value based on value verification after focus lost
    primarykey
    data
    text
    <p>I post new question based on this previously code posted here (<a href="https://stackoverflow.com/questions/14693177/filter-users-values-on-textfield-input-after-a-binddirectional-strategy-betwen-a">Filter users values on TextField input after a BindDirectional strategy betwen a Slider and min/max TextField</a>) </p> <p>My goal is simple, what is the best way to undo wrong <code>TextField</code> value (based on custom verification) after user lost the focus event on my value. </p> <p>Only way is to access the oldValue before user overwrite with another focus event ?</p> <p>Actually i have this simple code : </p> <pre><code>val myTextField = new TextField () def parseDouble(s: String) = try { Some(s.toDouble) } catch { case _ ⇒ None } myTextField.focusedProperty().addListener( new ChangeListener[java.lang.Boolean]() { override def changed(observable: ObservableValue[_ &lt;: java.lang.Boolean], oldValue: java.lang.Boolean, newValue: java.lang.Boolean) { if (!newValue) { parseDouble(myTextField.textProperty().get()) match { case Some(d: Double) ⇒ // test on the double value entered by user case _ ⇒ // code to reset to old value ?? } } } }) </code></pre> <p><strong>Update 1 :</strong> </p> <p>I find discussion here : <a href="https://forums.oracle.com/forums/thread.jspa?threadID=2382472" rel="nofollow noreferrer">https://forums.oracle.com/forums/thread.jspa?threadID=2382472</a> about <strong>undo functionnality for TextField/TextArea</strong> and other source code about <code>TextInputControlBehavior</code> : <a href="https://forums.oracle.com/forums/thread.jspa?threadID=2438759&amp;tstart=45" rel="nofollow noreferrer">https://forums.oracle.com/forums/thread.jspa?threadID=2438759&amp;tstart=45</a></p> <p>I find description of undo behavior implemented into javafx 2.2 here <a href="http://javafx-jira.kenai.com/browse/RT-7547" rel="nofollow noreferrer">http://javafx-jira.kenai.com/browse/RT-7547</a> but i cannot find sample code...</p> <p><strong>Update 2 :</strong> </p> <p>I find a post for public undo control API (roadmap fixed for 2.2.6) for <code>TextInputControl</code> here : <a href="http://javafx-jira.kenai.com/browse/RT-26575" rel="nofollow noreferrer">http://javafx-jira.kenai.com/browse/RT-26575</a></p> <p><code>TextInputBehaviorControl</code> can be see here : <a href="https://bitbucket.org/shemnon/openjfx-rt/src/6696e9cea59c401d2637d82f9cf96a515d210203/javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/TextInputControlBehavior.java" rel="nofollow noreferrer">https://bitbucket.org/shemnon/openjfx-rt/src/6696e9cea59c401d2637d82f9cf96a515d210203/javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/TextInputControlBehavior.java</a></p> <p><strong>Update 3 :</strong> </p> <p><strong><em>Tadam !</em></strong></p> <p>Finally i found an horrible way to do that, i hope public API is for 2.2.6 version of javaFX ...</p> <pre><code> val myTextField = new TextField () def parseDouble(s: String) = try { Some(s.toDouble) } catch { case _ ⇒ None } myTextField.focusedProperty().addListener( new ChangeListener[java.lang.Boolean]() { db ⇒ override def changed(observable: ObservableValue[_ &lt;: java.lang.Boolean], oldValue: java.lang.Boolean, newValue: java.lang.Boolean) { if (!newValue) { parseDouble(myTextField.textProperty().get()) match { case Some(d: Double) ⇒ if (myTextField.minValue &gt; d || d &gt; myTextField.maxValue) { doubleField.getSkin.asInstanceOf[TextInputControlSkin[_, _]].getBehavior.asInstanceOf[TextInputControlBehavior[_]].callAction("Undo") } else { // Here you change value property of textField } case _ ⇒ myTextField.getSkin.asInstanceOf[TextInputControlSkin[_, _]].getBehavior.asInstanceOf[TextInputControlBehavior[_]].callAction("Undo") } } } }) </code></pre> <p>I validate the answer if anybody find a better way to do that :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload