删除Alert的左侧填充

时间:2015-06-01 16:17:29

标签: javafx alert javafx-8 padding

考虑这个示例程序,它将TabPane添加到Alert中。正如您将看到的,TabPane左侧有一个白色衬垫,我无法移除。

如果有人知道它会很棒。

代码:

    import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

public class AlertTest extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        Scene scene = new Scene(new HBox());
        primaryStage.setScene(scene);
        primaryStage.show();

        Alert alert = new Alert(Alert.AlertType.NONE);
        alert.setTitle("");
        alert.initOwner(primaryStage);
        TabPane tabPane = new TabPane(new Tab("test"));
        tabPane.setPadding(Insets.EMPTY);
        alert.getDialogPane().setPadding(Insets.EMPTY);
        alert.getDialogPane().setContent(tabPane);
        alert.show();
    }
}

视觉: Ugly left padding

1 个答案:

答案 0 :(得分:1)

如果你这样添加css:

 public void start(Stage primaryStage) throws Exception {
    Scene scene = new Scene(new HBox());
    primaryStage.setScene(scene);

    //add this 3 lines
    String css = Main.class.getResource("styles.css").toExternalForm();
    scene.getStylesheets().clear();
    scene.getStylesheets().add(css);

    ...
}

并在styles.css中添加

.dialog-pane:no-header .graphic-container {
    -fx-padding: 0; /* 10px 0px 0px 10px */
}

您可以在文件中找到有关默认样式的更多信息:fxrt.jar!/com/sun/javafx/scene/control/skin/modena/modena.css

这是结果和full code demo

enter image description here

相关问题