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

JavaFx Menu doesn't close when clicking outside the Menu inside a Swing component

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P3 P3
    • 8u40
    • 8u25
    • javafx
    • None

      Please note this test may take multiple attempts to reproduce but it will occur and once it occurs, it remains in that state.

      1. Launch the attached code sample containing an Fx Menu and a standard swing JTextField.

      2. Click on the Menu. Once the drop down appears click inside the JTextField region

      Observe that the Menu doesn't close. If it doesn't occur the first time, keep opening the menu and clicking inside the JTextField. You will eventually see the menu will stop closing in response to clicking inside the text field.

      Additionally, observe that it takes two clicks to open the Menu after the JTextField is given focus.


      /////////////////////////////////////////////////////////////////////////////////////////////////////

      public class FxSwing {

        private static void initAndShowGUI() {
          // This method is invoked on the EDT thread
          JFrame frame = new JFrame("Swing and JavaFX");
          Panel contentPane = new Panel(new GridLayout(2, 1));
          final JFXPanel fxPanel = new JFXPanel();
          contentPane.add(fxPanel);
          contentPane.add(new JTextArea("Here is some text"));

          frame.add(contentPane);

          frame.setSize(300, 200);
          frame.setVisible(true);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

          Platform.runLater(new Runnable() {
            @Override
            public void run() {
              initFX(fxPanel);
            }
          });
        }

        private static void initFX(JFXPanel fxPanel) {
          // This method is invoked on the JavaFX thread
          Scene scene = createScene();
          fxPanel.setScene(scene);
        }

        private static Scene createScene() {
          Group root = new Group();
          Scene scene = new Scene(root, Color.ALICEBLUE);
          Text text = new Text();

          MenuBar menuBar = new MenuBar();

          Menu menuFile = new Menu("Menu");

          menuFile.getItems().addAll(new MenuItem("item 1"),
            new MenuItem("item 2"),
            new MenuItem("item 3"),
            new MenuItem("item 4"));

          menuBar.getMenus().addAll(menuFile);
          root.getChildren().addAll(menuBar);

          return (scene);
        }

        public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
              initAndShowGUI();
            }
          });
        }
      }

            ant Anton Tarasov (Inactive)
            dkamaljfx Danesh Kamal (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: