ADDITIONAL SYSTEM INFORMATION :
Window 10 Enterprise Version 1803
Tested on JDK 8 and JDK 13 with JavaFX13
A DESCRIPTION OF THE PROBLEM :
When the text of a Menu in e.g. a MenuButton changes to a shorter text, the width of the Menu becomes shorter than that of the parent and the triangle indicating that it's a Menu is moved away from the right border.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Have a MenuButton with a Menu and at least one other MenuItem. Execute a function, that gives the Menu a longer text. Switch back to shorter text.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The width of the menu should return to the one fitting the shorter text.
ACTUAL -
The width of the Popup stays wider, the width of the Menu is shortened, moving the triangle away from the right border.
---------- BEGIN SOURCE ----------
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuButton;
import javafx.scene.control.MenuItem;
import javafx.scene.control.ToolBar;
import javafx.stage.Stage;
public class MenuWidthDemo extends Application {
private static final String shortText = "Short text";
private static final String longText = "A long text for demonstration";
private ToolBar bar = new ToolBar();
private MenuButton button = new MenuButton("Menu");
private MenuItem switchItem = new MenuItem("Switch Text");
private Menu menu = new Menu(shortText);
private MenuItem otherItem = new MenuItem("other item");
private MenuItem otherSubItem = new MenuItem("item");
private Menu otherMenu = new Menu("other Menu");
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
switchItem.setOnAction(event -> {
if (shortText.equals(menu.getText())) {
menu.setText(longText);
} else {
menu.setText(shortText);
}
});
menu.getItems().add(switchItem);
button.getItems().add(otherItem);
button.getItems().add(menu);
otherMenu.getItems().add(otherSubItem);
button.getItems().add(otherMenu);
bar.getItems().add(button);
Scene scene = new Scene(bar);
primaryStage.setScene(scene);
primaryStage.show();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
When changing the text, remove the Menu before and add it back in after.
FREQUENCY : always
Window 10 Enterprise Version 1803
Tested on JDK 8 and JDK 13 with JavaFX13
A DESCRIPTION OF THE PROBLEM :
When the text of a Menu in e.g. a MenuButton changes to a shorter text, the width of the Menu becomes shorter than that of the parent and the triangle indicating that it's a Menu is moved away from the right border.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Have a MenuButton with a Menu and at least one other MenuItem. Execute a function, that gives the Menu a longer text. Switch back to shorter text.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The width of the menu should return to the one fitting the shorter text.
ACTUAL -
The width of the Popup stays wider, the width of the Menu is shortened, moving the triangle away from the right border.
---------- BEGIN SOURCE ----------
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuButton;
import javafx.scene.control.MenuItem;
import javafx.scene.control.ToolBar;
import javafx.stage.Stage;
public class MenuWidthDemo extends Application {
private static final String shortText = "Short text";
private static final String longText = "A long text for demonstration";
private ToolBar bar = new ToolBar();
private MenuButton button = new MenuButton("Menu");
private MenuItem switchItem = new MenuItem("Switch Text");
private Menu menu = new Menu(shortText);
private MenuItem otherItem = new MenuItem("other item");
private MenuItem otherSubItem = new MenuItem("item");
private Menu otherMenu = new Menu("other Menu");
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
switchItem.setOnAction(event -> {
if (shortText.equals(menu.getText())) {
menu.setText(longText);
} else {
menu.setText(shortText);
}
});
menu.getItems().add(switchItem);
button.getItems().add(otherItem);
button.getItems().add(menu);
otherMenu.getItems().add(otherSubItem);
button.getItems().add(otherMenu);
bar.getItems().add(button);
Scene scene = new Scene(bar);
primaryStage.setScene(scene);
primaryStage.show();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
When changing the text, remove the Menu before and add it back in after.
FREQUENCY : always