目录
一、环境
jdk8
二、模拟
三、代码
package xyz.hashdog.class30;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
/**
* @author th
* @description: TODO
* @projectName hashdog
* @date 2020/2/1620:48
*/
public class Launch extends Application {
public static void main(String[] args) {
Application.launch(Launch.class,args);
}
@Override
public void start(Stage primaryStage) throws Exception {
AnchorPane an = new AnchorPane();
TabPane tabPane = new TabPane();
tabPane.setPrefHeight(300.0);
tabPane.setPrefWidth(300.0);
//给tb1设置水平布局面板
Tab tb1 = new Tab("tb1");
HBox hbox = new HBox();
hbox.setStyle("-fx-background-color: deeppink");
hbox.setAlignment(Pos.CENTER);
hbox.getChildren().addAll(new Button("bt1"),new Button("bt2"));
tb1.setContent(hbox);
//给tb2设置垂直布局面板
Tab tb2 = new Tab("tb2");
VBox vbox = new VBox();
vbox.setStyle("-fx-background-color: hotpink");
vbox.setAlignment(Pos.CENTER);
vbox.getChildren().addAll(new Button("bt3"),new Button("bt4"));
tb2.setContent(vbox);
Tab tb3 = new Tab("tb3");
tabPane.getTabs().addAll(tb1,tb2,tb3);
AnchorPane.setTopAnchor(tabPane,20.0);
AnchorPane.setLeftAnchor(tabPane,20.0);
an.getChildren().addAll(tabPane);
an.setStyle("-fx-background-color: deepskyblue");
Scene s= new Scene(an);
primaryStage.setScene(s);
primaryStage.setTitle("hashdog");
primaryStage.setWidth(500);
primaryStage.setHeight(300);
//设置窗口不可拉伸
primaryStage.setResizable(false);
primaryStage.show();
}
}