0

I have a JavaFX Alert dialog with several ButtonTypes that I have added.

Problem is, when I add the button that is larger (text is longer), the rest of the buttons start to stretch out from the original size.

like this:

enter image description here

Where it should look like this:

enter image description here

Is there a way to make it so that all buttons use their preferred size?

Here is the code:

    ButtonType saveButtonType = new ButtonType("Save", ButtonBar.ButtonData.OK_DONE);
    ButtonType closeButtonType = new ButtonType("Close", ButtonBar.ButtonData.CANCEL_CLOSE);
    ButtonType testButtonType = new ButtonType("LONG BUTTON TEXT", ButtonBar.ButtonData.LEFT);

    dialog.getDialogPane().getButtonTypes().addAll(saveButtonType, closeButtonType,testButtonType);
trilogy
  • 1,738
  • 15
  • 31

1 Answers1

3

Figured it out:

Button testButton = (Button) dialog.getDialogPane().lookupButton(testButtonType);
ButtonBar.setButtonUniformSize(testButton, false);
trilogy
  • 1,738
  • 15
  • 31