小编Und*_*and的帖子

如何通过在 FXML 中使用 BorderPane 对齐来对齐 HBox?

我想要的是将 HBox 按钮对齐到对话框底部的中心。我想在 fxml 中执行此操作。但是,BorderPane 对齐在标签中起作用。这是我这边的代码。我认为即使标签是底部,BorderPane.alignment="BOTTOM_CENTER" 也必须工作。

类文件:

package application;

import java.io.IOException;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class HBoxDialog extends Application {

@Override
public void start(Stage primaryStage) {
    try {
        Parent root = FXMLLoader.load(getClass().getResource("HBoxDialog.fxml"));
        primaryStage.setScene(new Scene(root, 500, 100));
        primaryStage.show();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

public static void main(String[] args) {
    launch(args);
}
}
Run Code Online (Sandbox Code Playgroud)

FXML 文件:

<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.layout.BorderPane?>
<BorderPane …
Run Code Online (Sandbox Code Playgroud)

java javafx fxml

3
推荐指数
1
解决办法
3272
查看次数

标签 统计

fxml ×1

java ×1

javafx ×1