首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >具有边框颜色的Javafx自定义DialogPane在每次按键时都会缩小

具有边框颜色的Javafx自定义DialogPane在每次按键时都会缩小
EN

Stack Overflow用户
提问于 2017-07-01 19:24:15
回答 1查看 418关注 0票数 0

我已经在Javafx中创建了一个自定义对话框。我面临的问题是,每当我按下任何键时,对话框窗格的大小都会缩小。

自定义对话框的代码如下

代码语言:javascript
复制
package javafxcustomdialog;

import java.util.List;
import java.util.Optional;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.control.DialogPane;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;


public class JavafxCustomDialog extends Application {

    @Override
    public void start(Stage primaryStage) {
        Dialog dialog = new Dialog();
        DialogPane dialogPane = dialog.getDialogPane();
        dialog.setHeaderText(null);
        dialog.setGraphic(null);
        dialog.initStyle(StageStyle.UNDECORATED);
        dialog.initModality(Modality.APPLICATION_MODAL);
        dialog.getDialogPane().setStyle("-fx-background-color: #fff; -fx-border-color: #e7eaec #e7eaec #e7eaec #e7eaec; -fx-border-width: 6;");

        // Set the button types.
        ButtonType okButtonType = new ButtonType("Ok", ButtonBar.ButtonData.OK_DONE);
        ButtonType cancelButtonType = new ButtonType("Cancel", ButtonBar.ButtonData.CANCEL_CLOSE);
        dialog.getDialogPane().getButtonTypes().addAll(okButtonType, cancelButtonType);

        // VBox
        VBox alertVBox = new VBox();
        VBox.setVgrow(alertVBox, Priority.ALWAYS);
        alertVBox.setPrefWidth(400.0);
        alertVBox.setSpacing(10);
        Label label = new Label("Enter Some Text");
        TextField textField = new TextField();
        alertVBox.getChildren().addAll(label, textField);
        // END VBox

        dialog.getDialogPane().setContent(alertVBox);
        // Request focus on the username field by default.
        Platform.runLater(() -> textField.requestFocus());

        // result
        Optional<List<String>> result = dialog.showAndWait();
        if (result.isPresent()) {
            System.out.println("Good");
        } else {
            System.out.println("Something is wrong..!!");
        }

    }

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

}

问题出在这一行

代码语言:javascript
复制
dialog.getDialogPane().setStyle("-fx-background-color: #fff; -fx-border-color: #e7eaec #e7eaec #e7eaec #e7eaec; -fx-border-width: 6;");

截图:

EN

回答 1

Stack Overflow用户

发布于 2017-07-03 15:47:32

对于面临同样问题的人,解决方案就是将你的java SE从8u40升级到8u60或更高版本。这是java SE https://bugs.openjdk.java.net/browse/JDK-8095678中的一个错误

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44860340

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档