I am a scala newbie who came from JavaFX 1.3 and this is my first post in stackoverflow
In JavaFX 1.3 I can do something like this
property : bind if (condition) value1 else value2
In Scala, I attempted doing something like this:
property <== function1
def function1() = {
if (condition)
value1
else
value2
}
However, it does not seem to be dynamically working. The expression in the condition of the function evaluates only once when the stage appears. I was kind of expecting the values in that expression are evaluated in realtime.
Specifically, I want to resize something to a certain limit and I am using binding to achieve it. So I want the bound function to keep evaluating the expression and give me the appropriate width of something as I resize other things.
Anyway, I will paste the actual codes below:
var stageWidth = DoubleProperty(0)
var stageHeight = DoubleProperty(0)
stageWidth <== stage.scene.width
stageHeight <== stage.scene.height
var origStageWidth = DoubleProperty(stage.scene.width.toDouble)
val origStageHeight = DoubleProperty(stage.scene.height.toDouble)
val origTextClipperWidth = DoubleProperty(textClipper.width.toDouble)
val origTextClipperHeight = DoubleProperty(textClipper.height.toDouble)
val minWidth = DoubleProperty(100)
val origButtonWidth = DoubleProperty(button.prefWidth.toDouble)
textClipper.width <== resize
def resize() ={
var boolResult = (stageWidth - origStageWidth) + origTextClipperWidth > minWidth
if (boolResult.value) {
(stageWidth - origStageWidth) + origTextClipperWidth
} else {
minWidth
}
}
textClipper.height <== (stageHeight - origStageHeight) + origTextClipperHeight
Thanks in advance for your help.