1
行爲是否像javafx2綁定中的錯誤? 獨立應用程序本身總是自我通知自己的狀態(xPosition,yPosition,高度,寬度等)似乎是合乎邏輯的。 我正在閱讀的書籍「Pro JavaFX 2使用Java技術的富客戶端權威指南」和一些代碼示例根本無法正常工作。注意:我在這裏使用的代碼是我的。 (這本書是有關?)如何在沒有偵聽器的情況下綁定一個stage屬性?
package simplejavafxbindingquestion;
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.event.EventHandler;
import javafx.geometry.VPos;
import javafx.scene.Scene;
import javafx.scene.SceneBuilder;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBuilder;
import javafx.scene.control.Label;
import javafx.scene.control.LabelBuilder;
import javafx.scene.layout.HBox;
import javafx.scene.layout.HBoxBuilder;
import javafx.scene.layout.Pane;
import javafx.scene.layout.PaneBuilder;
import javafx.scene.layout.VBox;
import javafx.scene.layout.VBoxBuilder;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.scene.text.TextBuilder;
import javafx.stage.Stage;
public class SimpleJavaFXBindingQuestion extends Application {
@Override
public void start(final Stage stage) {
Text textBoundStageHeight;
Text textRequestedStageHeight;
final Label labelRequestedStageHeight;
VBox vBox;
HBox hBox;
Button btnRequest;
Pane sceneRoot = PaneBuilder.create()
.children(
vBox = VBoxBuilder.create()
.spacing(10)
.children(
textBoundStageHeight = TextBuilder.create()
.textOrigin(VPos.TOP)
.font(Font.font("Ariel", 20))
.build(),
hBox = HBoxBuilder.create()
.children(
textRequestedStageHeight = TextBuilder.create()
.textOrigin(VPos.TOP)
.font(Font.font("Ariel", 20))
.text("requested stage height: ")
.build(),
labelRequestedStageHeight = LabelBuilder.create()
.font(Font.font("Ariel", 20))
.text("Unknown")
.build()
)
.build(),
btnRequest = ButtonBuilder.create()
.text("Request height!")
.font(Font.font("Ariel", 15))
.onAction(new EventHandler<javafx.event.ActionEvent>() {
@Override
public void handle(javafx.event.ActionEvent event) {
labelRequestedStageHeight.setText("" + stage.getHeight());
}
})
.build()
)
.build()
)
.build();
textBoundStageHeight.textProperty()
.bind(new SimpleStringProperty("bound stage height: ")
.concat(stage.getHeight()));
Scene scene = SceneBuilder.create()
.root(sceneRoot)
.build();
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}