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());
}
}
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());
}
}
- relates to
-
JDK-8200224 First mouse press each time JFXPanel gains focus is triggered twice
-
- Resolved
-
-
JDK-8090000 [JFXPanel] scene doesn't gain focus when node programatically focused
-
- Closed
-
-
JDK-8095645 JavaFx Menu doesn't close when clicking outside the Menu inside a Swing component
-
- Closed
-