私はJavaFX 1.3から来たscala初心者で、これがstackoverflowでの最初の投稿です
JavaFX 1.3では、このようなことができます
property : bind if (condition) value1 else value2
Scala では、次のようなことを試みました。
property <== function1
def function1() = {
if (condition)
value1
else
value2
}
ただし、動的に動作しているようには見えません。関数の条件の式は、ステージが表示されたときに 1 回だけ評価されます。その式の値がリアルタイムで評価されることを期待していました。
具体的には、何かを特定の制限までサイズ変更したいので、バインディングを使用してそれを達成しています。したがって、バインドされた関数が式を評価し続け、他のもののサイズを変更するときに何かの適切な幅を与えてほしい.
とにかく、実際のコードを以下に貼り付けます。
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
よろしくお願いします。