-
Bug
-
Resolution: Won't Fix
-
P4
-
None
-
fx2.1
-
Windows 7, JavaFX 2.1 beta b12
The graphic of a MenuItem disappears if there are several Menus, which share the same MenuItems. In my use case I have to share them among a Menu and a MenuButton. (both menus' items should always have the same state and so on, e.g. selected, text, graphic, action.)
To reproduce, run the code below. Click on "Menu", then click on "Button", then click on "Menu" again. Notice that the red buttons are no longer displayed in the "Menu", (but are still displayed in the "Button").
It also works the other way round, if you first click "Button", then "Menu", then "Button".
It also works, if you use a second MenuButton instead of a MenuBar.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class TestApp3 extends Application {
public static void main(String[] args) throws Exception {
launch(args);
}
public void start(final Stage stage) throws Exception {
VBox root = new VBox();
MenuBar menuBar = new MenuBar();
Menu menu = new Menu("Menu");
menuBar.getMenus().addAll(menu);
MenuButton menuButton = new MenuButton("Button");
for (int i = 0; i < 5; i++) {
MenuItem menuItem = new RadioMenuItem("MenuItem" + i);
Button button = new Button("x");
button.setStyle("-fx-background-color: red;");
menuItem.setGraphic(button);
menu.getItems().add(menuItem);
menuButton.getItems().add(menuItem);
}
root.getChildren().addAll(menuBar, menuButton);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
}
To reproduce, run the code below. Click on "Menu", then click on "Button", then click on "Menu" again. Notice that the red buttons are no longer displayed in the "Menu", (but are still displayed in the "Button").
It also works the other way round, if you first click "Button", then "Menu", then "Button".
It also works, if you use a second MenuButton instead of a MenuBar.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class TestApp3 extends Application {
public static void main(String[] args) throws Exception {
launch(args);
}
public void start(final Stage stage) throws Exception {
VBox root = new VBox();
MenuBar menuBar = new MenuBar();
Menu menu = new Menu("Menu");
menuBar.getMenus().addAll(menu);
MenuButton menuButton = new MenuButton("Button");
for (int i = 0; i < 5; i++) {
MenuItem menuItem = new RadioMenuItem("MenuItem" + i);
Button button = new Button("x");
button.setStyle("-fx-background-color: red;");
menuItem.setGraphic(button);
menu.getItems().add(menuItem);
menuButton.getItems().add(menuItem);
}
root.getChildren().addAll(menuBar, menuButton);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
}
- relates to
-
JDK-8114324 Graphic issue in SplitButton with menu item only
-
- Closed
-