将按钮文本缩放到按钮大小(反之亦然)

问题描述 投票:2回答:1

我有一个如下所示的简单警报,在Windows和Linux中显示不同。有很多帖子可以根据文字缩放按钮大小,但我基本上想要相反。按钮应保持相同的大小,文本应缩放以适合(就像它似乎在窗口中做)

protected static void setDifficulty(){

    Alert alert = new Alert(AlertType.CONFIRMATION);
    alert.setTitle("Welcome to the game of Memory");
    alert.setHeaderText("How difficult should your oppenent be?");
    alert.setContentText("Please choose your desired difficulty.");

    ButtonType button1 = new ButtonType("Nice n' Easy");
    ButtonType button2 = new ButtonType("So So");
    ButtonType button3 = new ButtonType("Super Freak");
    ButtonType buttonCancel = new ButtonType("Cancel", ButtonData.CANCEL_CLOSE);

    alert.getButtonTypes().setAll(button1, button2, button3, buttonCancel);

    Optional<ButtonType> result = alert.showAndWait();
    if (result.get() == button1){
        MemoryField.difficulty = 10;
    } else if (result.get() == button2) {
        MemoryField.difficulty = 5;
    } else if (result.get() == button3) {
        MemoryField.difficulty = 0;
    } else {
        Platform.exit();
    }
}

在Windows上:

在Ubuntu上:

javafx-8 alerts platform-specific
1个回答
0
投票

我能够在Linux上避免此问题的唯一方法是获取按钮的句柄,并设置首选宽度:

    for(ButtonType buttonType : alert.getButtonTypes()){
        Button button = (Button) alert.getDialogPane().lookupButton(buttonType);
        button.setPrefWidth(100);
    }
© www.soinside.com 2019 - 2024. All rights reserved.