各种容器的关系如下图所示,其中,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
转载于:https://blog.51cto.com/fengbin8606/1421711