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

[JFXPanel] Clicking on Menu in JFXPanel ignored if another swing component has focus

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 8u25
    • Fix Version/s: 10
    • Component/s: javafx
    • Labels:
      None

      Description

      The following test program (a slightly modified version of the one from RT-39621 to avoid using an AWT component since it doesn't affect the test) will illustrate this.

      Steps:

      1) Run the program
      2) Click in the JTextField at the bottom
      3) BUG: Click on the "Menu" and notice that the pull down menu doesn't popup
      4) Click on it again and it is fine

      If you click anywhere in the top JFXPanel before clicking on the menu (between steps 2 and 3), then it is also fine.


      -----------------------------------------------------------------------------------------------------------------

      import java.awt.GridLayout;
      import javafx.application.Platform;
      import javafx.embed.swing.JFXPanel;
      import javafx.scene.Group;
      import javafx.scene.Scene;
      import javafx.scene.control.Menu;
      import javafx.scene.control.MenuBar;
      import javafx.scene.control.MenuItem;
      import javafx.scene.paint.Color;
      import javax.swing.JFrame;
      import javax.swing.JPanel;
      import javax.swing.JTextArea;
      import javax.swing.SwingUtilities;

      public class FxSwing {

          private static void initAndShowGUI() {
              // This method is invoked on the EDT thread
              JFrame frame = new JFrame("Swing and JavaFX");
              JPanel contentPane = new JPanel(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(() -> 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);

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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              psadhukhan Prasanta Sadhukhan
              Reporter:
              kcr Kevin Rushforth
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported: