JDK-8095645 : JavaFx Menu doesn't close when clicking outside the Menu inside a Swing component
  • Type: Bug
  • Component: javafx
  • Sub-Component: swing
  • Affected Version: 8u25
  • Priority: P3
  • Status: Closed
  • Resolution: Cannot Reproduce
  • Submitted: 2014-12-08
  • Updated: 2015-06-12
  • Resolved: 2014-12-10
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8u40Resolved
Related Reports
Relates :  
Description
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();
      }
    });
  }
}
Comments
I'm going to mark this as not reproducible in 8u40. If it happens in 8u40, please reopen with any additional information needed to reproduce it.
10-12-2014

I was testing this with 8u25 on a Windows 7 platform. I'll retest with 8u40 and provide an update
09-12-2014

> Additionally, observe that it takes two clicks to open the Menu after the JTextField is given focus. I do still see this. Clicking anywhere in the JFXPanel and then clicking on the Menu will open the menu. This seems to be an unrelated issue. I filed RT-39623 to track this other issue.
08-12-2014

I see that this happens in 8u25, but I cannot reproduce this in 8u40. Please confirm which JDK you are running. If 8u25, then please download the latest early access build of 8u40 here: https://jdk8.java.net/download.html
08-12-2014