Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>as I am currently working on a JavaFX with Scala solution too, I would like to try your example, but I can't get it compiled. Specifically <code>doubleField</code> and <code>value.set</code> are unknown!</p> <p>I have some hints - First: there is an obvious code duplication, that could be easily solved by adding a condition to the case - the first case only holds if the condition (d in range) is fulfilled</p> <pre><code>case Some(d: Double) if (doubleField.minValue &lt;= d &amp;&amp; d &lt;= doubleField.maxValue) ⇒ value.set(d) case _ ⇒ doubleField.getSkin.asInstanceOf[TextInputControlSkin[_, _]].getBehavior.asInstanceOf[TextInputControlBehavior[_]].callAction("Undo") </code></pre> <p>Second: provide a wrapper for anonymous inner classes in Java - for instance the above ChangeListener could be wrapped like this:</p> <pre><code>implicit def unit2ChangeListener[T](f: (ObservableValue[_ &lt;: T], T, T) =&gt; Unit) = new ChangeListener[T] { override def changed(observable: ObservableValue[_ &lt;: T], oldValue: T, newValue: T) { f(observable, oldValue, newValue) } } </code></pre> <p>These implicit conversions could be hidden in a util class (along with a nice unit2EventHandler) and imported to your application. This would lead to something a bit more readable (but still a little painful):</p> <pre><code>myTextField.focusedProperty().addListener( (observable: ObservableValue[_ &lt;: java.lang.Boolean], oldValue: java.lang.Boolean, newValue: java.lang.Boolean) =&gt; if (!newValue) { ... } ) </code></pre> <p>Probably <a href="http://code.google.com/p/scalafx/" rel="nofollow">ScalaFx</a> already provides something like this, but I haven't tried it yet.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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