Javafx 8 对话框额外边框

Javafx 8 dialog extra borders

问题: 对话框中的额外边框,我想将其删除。

描述: 我创建了一个简单的应用程序,它带有一个显示对话框的按钮。我将带有绿色背景的锚定窗格设置为对话框的内容。此锚定窗格包含另一个具有黑色背景的锚定窗格,它锚定到父级以填充整个 space。理论上我不应该看到任何绿色区域,只能看到黑色区域。但事实并非如此,它们就像绿色边框。

为什么?感谢您的帮助!

screenshot of the problem

package testdialog;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Dialog;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;


public class TestDialog extends Application {

    @Override
    public void start(Stage primaryStage) {
        Button btn = new Button();
        btn.setText("Show dialog");
        btn.setOnAction((ActionEvent event) -> {
            AnchorPane content = new AnchorPane();
            content.setStyle("-fx-background-color: green; -fx-border-color: red;");
            content.setPrefSize(100, 100);

            AnchorPane innerAnchorPane = new AnchorPane();
            innerAnchorPane.setStyle("-fx-background-color: black;");
            AnchorPane.setTopAnchor(innerAnchorPane, 0d);
            AnchorPane.setRightAnchor(innerAnchorPane, 0d);
            AnchorPane.setBottomAnchor(innerAnchorPane, 0d);
            AnchorPane.setLeftAnchor(innerAnchorPane, 0d);

            content.getChildren().add(innerAnchorPane);

            Dialog dlg = new Dialog();
            dlg.getDialogPane().getStyleClass().add("customDialog");
            dlg.initOwner(primaryStage);
            dlg.getDialogPane().setContent(content);
            dlg.initStyle(StageStyle.UNDECORATED);
            dlg.initModality(Modality.NONE);
            dlg.show();
        });

        StackPane root = new StackPane();
        root.setStyle("-fx-background-color: yellow;");
        root.getChildren().add(btn);

        Scene scene = new Scene(root, 300, 250);
        scene.getStylesheets().add(getClass().getResource("style.css").toExternalForm());

        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }

}

css 文件 (style.css)。 customDialog class只是去掉对话框的按钮栏。

.customDialog > *.button-bar > *.container {
    -fx-pref-height: 0;
}

默认样式sheet,modena.css有如下规则:

.dialog-pane > .content {
    -fx-padding: 0.833em; /* 10 */
}

向对话框窗格的内容添加 10 个像素的填充。

您可以在对话框中用

覆盖它
.customDialog .content {
    -fx-padding: 0 ;
}

在您的 style.css 文件中。