FULL PRODUCT VERSION :
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux blue 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt25-2+deb8u2 (2016-06-25) x86_64 GNU/Linux
EXTRA RELEVANT SYSTEM CONFIGURATION :
Gnome Classic 3.14.1
A DESCRIPTION OF THE PROBLEM :
javafx.scene.control.Labeled always acts as if its mnemonicParsing property is false when computing its preferred size. As a result, if the text contains an underscore character, a Labeled control’s preferred width is always wide enough to accommodate the underscore, even if mnemonicParsing is set to true, causing the underscore not to be rendered.
This causes the component to appear too wide. This is not very noticeable with Labels and Buttons, but it is quite noticeable with Menus in a MenuBar, as the extra width causes the text of the Menus to be spaced very far apart from one another, making the MenuBar jarringly different in appearance from native menu bars.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Place two controls in a JavaFX application which are identical except for their mnemonicParsing properties and the presence of an underscore character in their text. Compare their default sizes.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Labeled should take the mnemonicParsing property into account when computing its preferred width. When mnemonicParsing is true and the text property contains an underscore character, the preferred width should accommodate the text as if the underscore is not present at all.
ACTUAL -
All subclasses of Labeled currently base their preferred width on the raw value of the text property, including any underscore character, regardless of whether they actually display the underscore.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
public class MnemonicParsingSizeDemo
extends Application {
@Override
public void start(Stage stage) {
Label label1 = new Label("_Name:");
Label label2 = new Label("Name:");
label1.setMnemonicParsing(true);
Button button1 = new Button("_Save");
Button button2 = new Button("Save");
button1.setMnemonicParsing(true);
HBox[] rows = {
new HBox(0, label1, new TextField()),
new HBox(0, label2, new TextField()),
new HBox(0, button1),
new HBox(0, button2),
};
for (HBox row : rows) {
row.setAlignment(Pos.BASELINE_LEFT);
}
VBox pane = new VBox(3, rows);
pane.setPadding(new Insets(6));
Scene scene = new Scene(pane);
stage.setScene(scene);
stage.setTitle("MnemonicParsing Size Demo");
stage.show();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
In theory, one could override the computePrefWidth(double) method of a control whose mnemonicParsing property is true, and return a value obtained from the prefWidth(double) method of a second, non-visible control of the same class with the same properties, except with mnemonicParsing set to false.
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux blue 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt25-2+deb8u2 (2016-06-25) x86_64 GNU/Linux
EXTRA RELEVANT SYSTEM CONFIGURATION :
Gnome Classic 3.14.1
A DESCRIPTION OF THE PROBLEM :
javafx.scene.control.Labeled always acts as if its mnemonicParsing property is false when computing its preferred size. As a result, if the text contains an underscore character, a Labeled control’s preferred width is always wide enough to accommodate the underscore, even if mnemonicParsing is set to true, causing the underscore not to be rendered.
This causes the component to appear too wide. This is not very noticeable with Labels and Buttons, but it is quite noticeable with Menus in a MenuBar, as the extra width causes the text of the Menus to be spaced very far apart from one another, making the MenuBar jarringly different in appearance from native menu bars.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Place two controls in a JavaFX application which are identical except for their mnemonicParsing properties and the presence of an underscore character in their text. Compare their default sizes.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Labeled should take the mnemonicParsing property into account when computing its preferred width. When mnemonicParsing is true and the text property contains an underscore character, the preferred width should accommodate the text as if the underscore is not present at all.
ACTUAL -
All subclasses of Labeled currently base their preferred width on the raw value of the text property, including any underscore character, regardless of whether they actually display the underscore.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
public class MnemonicParsingSizeDemo
extends Application {
@Override
public void start(Stage stage) {
Label label1 = new Label("_Name:");
Label label2 = new Label("Name:");
label1.setMnemonicParsing(true);
Button button1 = new Button("_Save");
Button button2 = new Button("Save");
button1.setMnemonicParsing(true);
HBox[] rows = {
new HBox(0, label1, new TextField()),
new HBox(0, label2, new TextField()),
new HBox(0, button1),
new HBox(0, button2),
};
for (HBox row : rows) {
row.setAlignment(Pos.BASELINE_LEFT);
}
VBox pane = new VBox(3, rows);
pane.setPadding(new Insets(6));
Scene scene = new Scene(pane);
stage.setScene(scene);
stage.setTitle("MnemonicParsing Size Demo");
stage.show();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
In theory, one could override the computePrefWidth(double) method of a control whose mnemonicParsing property is true, and return a value obtained from the prefWidth(double) method of a second, non-visible control of the same class with the same properties, except with mnemonicParsing set to false.
- duplicates
-
JDK-8089193 Width of menu is affected by mnemonic-identifier
-
- Resolved
-