JavaFX Mnemonic Parsing Creates Extra Space

582 Views Asked by At

When creating a JavaFX Application and enabling mnemonic parsing in your FXML files, you should be able to use an '_' character in the label string of a javafx.scene.control.Menu to allow parsing to an Alt code (on Windows). This works, but it appears that there is an extra space in the width of the Menu when the Stage is shown, as confirmed in this bug report from 2014.

My question is as follows: does anyone know of any workarounds to fix this issue? I thought of calculating the size of the text itself and then manually setting the width of the Menu, but it does not appear that JavaFX's Menu has a setWidth(), widthProperty(), or other method to manually set the size.

I also thought of centering the text within the Menu, but could not find any means of accomplishing such through Java code, Scene Builder, or JavaFX's CSS.

Here is a screenshot of the issue:

enter image description here

Edit:

After some working with it, I found that you can do the following in CSS:

.menu-bar .menu .label {
    -fx-alignment: center;
}

This aligns the label of the JavaFX Menu to centered, but the extra space is still present. It works well enough to satisfy my OCD, but is there still a better way to handle this issue?

0

There are 0 best solutions below