import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.TextFieldTableCell;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class MergeMultiLevelHeaderInJavaFX extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
TableView<String> tableView = new TableView<>();
// 第一级表头
TableColumn<String, String> column1 = new TableColumn<>("个人信息");
TableColumn<String, String> column2 = new TableColumn<>("联系方式");
// 第二级表头 - 个人信息下的子表头
TableColumn<String, String> subColumn1 = new TableColumn<>("姓名");
TableColumn<String, String> subColumn2 = new TableColumn<>("年龄");
// 第二级表头 - 联系方式下的子表头
TableColumn<String, String> subColumn3 = new TableColumn<>("电话");
TableColumn<String, String> subColumn4 = new TableColumn<>("邮箱");
// 合并姓名和年龄的表头
subColumn1.setPrefWidth(150);
subColumn2.setPrefWidth(150);
subColumn1.setGraphic(new TextFieldTableCell<>());
subColumn2.setGraphic(new TextFieldTableCell<>());
subColumn1.setStyle("-fx-border-right: 0;");
subColumn2.setStyle("-fx-border-left: 0;");
column1.getColumns().addAll(subColumn1, subColumn2);
column2.getColumns().addAll(subColumn3, subColumn4);
tableView.getColumns().addAll(column1, column2);
}
}