Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8127236

Conflict with MenuButton and Menu / graphic disappears

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: fx2.1
    • Fix Version/s: None
    • Component/s: javafx
    • Environment:

      Windows 7, JavaFX 2.1 beta b12

      Description

      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();
          }
      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                leifs Leif Samuelsson (Inactive)
                Reporter:
                cschudtjfx Christian Schudt (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported: