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();
}
});
}
}
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();
}
});
}
}
- relates to
-
JDK-8087914 [JFXPanel] Clicking on Menu in JFXPanel ignored if another swing component has focus
-
- Resolved
-