各種容器的關係如下圖所示,其中,node是一個可視化的組件,如:形狀,圖片顯示窗口,UI控件,或者是Pane組件。
所有的Node組件都有一些相同的屬性,下面的程序介紹其中的兩個的用法:style 和 rotate
import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.stage.Stage; import javafx.scene.layout.StackPane; public class NodeStyleRotateDemo extends Application { public void start(Stage primaryStage) { StackPane pane = new StackPane(); Button btOK = new Button("OK"); btOK.setStyle("-fx-border-color:blue;"); pane.getChildren().add(btOK); pane.setRotate(45); pane.setStyle("-fx-border-color:red; -fx-background-color:lightgray;"); Scene scene = new Scene(pane,200,250); primaryStage.setTitle("NodeStyleRotateDemo"); primaryStage.setScene(scene); primaryStage.show(); } }
說明:
1、本程序運行的結果是
2、JavaFx的style屬性與CSS有許多相似之處,所以也叫JavaFx CSS。
3、在JavaFx中,style屬性用-fx-定義,每個node都有自己的style屬性,可以在
http://docs.oracle.com/javafx/2/api/javafx/scene/doc-files/c***ef.html中找到這些屬性的用法。
4、style屬性的語法是styleName:value