Pane
面板类主要有如下几种:栈面板类StackPane、边界面板类BorderPane、流式面板类
FlowPane、网格面板类GridePane、单行面板类HBox和单列面板类VBox等几种。
ps:一个节点只能添加到一个面板中
JavaFX CSS
sPane.setStyle("-fx-border-color: yellow;-fx-background-color: green");
bt1.setStyle("-fx-border-color: red");
StackPane
StackPane sPane = new StackPane();
sPane.getChildren().addAll(bt1,bt);
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
StackPane sPane = new StackPane();
Button bt = new Button("Button");
bt.setStyle("-fx-border-color: blue");
bt.setPrefSize(80,50);
Button bt1 = new Button("Button1");
bt1.setStyle("-fx-border-color: red");
bt1.setPrefSize(100,80);
bt.setRotate(-45);
sPane.setRotate(45);
sPane.setStyle("-fx-border-color: yellow;-fx-background-color: green");
sPane.getChildren().addAll(bt1,bt);
Scene sc = new Scene(sPane,180,100);
primaryStage.setTitle("StackPane");
primaryStage.setScene(sc);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}