Details
-
Bug
-
Resolution: Fixed
-
P3
-
8u5, 8u20
-
Mac OS X Java 8u20 (ea, downloaded on 25th of July 2014) and Java 8_u5
Description
By executing the following code and following the steps:
1- Right click on red panel -> context menu is shown (OK)
2- Left click into the grey area -> context menu is hidden (OK)
3- Right click on red panel -> context menu is not shown again (NOT OK)
It should show the context menu.
Note: Value of showingProperty is printed out.
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.layout.StackPane;
import javax.swing.*;
import java.awt.*;
public class ContextMenuTest {
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(() -> {
ContextMenuTest swingView = new ContextMenuTest();
swingView.createAndShowGUI();
});
}
private void createAndShowGUI() {
JFrame.setDefaultLookAndFeelDecorated(true);
//Create and set up the window
JFrame frame = new JFrame("Test Swing Frame");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
JPanel mainPanel = new JPanel();
mainPanel.setMinimumSize(new Dimension(600, 400));
mainPanel.setPreferredSize(mainPanel.getMinimumSize());
//add JavaFX panel to Swing main panel
final JFXPanel fxMainPanel = new JFXPanel();
mainPanel.add(fxMainPanel, "0,0");
Platform.setImplicitExit(false);
// create JavaFX scene
Platform.runLater(() -> createScene(fxMainPanel));
frame.getContentPane().add(mainPanel);
//Display the window
frame.pack();
frame.setVisible(true);
}
private void createScene(JFXPanel fxMainPanel) {
StackPane rootPane = new StackPane();
rootPane.setPrefSize(100.0, 100.0);
rootPane.setStyle("-fx-background-color: red");
ContextMenu contextMenu = new ContextMenu();
MenuItem menuItem = new MenuItem("Test Menu Item");
contextMenu.getItems().add(menuItem);
rootPane.setOnContextMenuRequested(event -> {
contextMenu.show(rootPane, event.getScreenX(), event.getScreenY());
System.out.println("Context menu requested");
event.consume();
});
contextMenu.showingProperty().addListener((observable, oldValue, newValue) -> System.out.println("Context menu showing old = " + oldValue + ", new = " + newValue));
Scene scene = new Scene(rootPane);
fxMainPanel.setScene(scene);
}
}
1- Right click on red panel -> context menu is shown (OK)
2- Left click into the grey area -> context menu is hidden (OK)
3- Right click on red panel -> context menu is not shown again (NOT OK)
It should show the context menu.
Note: Value of showingProperty is printed out.
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.layout.StackPane;
import javax.swing.*;
import java.awt.*;
public class ContextMenuTest {
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(() -> {
ContextMenuTest swingView = new ContextMenuTest();
swingView.createAndShowGUI();
});
}
private void createAndShowGUI() {
JFrame.setDefaultLookAndFeelDecorated(true);
//Create and set up the window
JFrame frame = new JFrame("Test Swing Frame");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
JPanel mainPanel = new JPanel();
mainPanel.setMinimumSize(new Dimension(600, 400));
mainPanel.setPreferredSize(mainPanel.getMinimumSize());
//add JavaFX panel to Swing main panel
final JFXPanel fxMainPanel = new JFXPanel();
mainPanel.add(fxMainPanel, "0,0");
Platform.setImplicitExit(false);
// create JavaFX scene
Platform.runLater(() -> createScene(fxMainPanel));
frame.getContentPane().add(mainPanel);
//Display the window
frame.pack();
frame.setVisible(true);
}
private void createScene(JFXPanel fxMainPanel) {
StackPane rootPane = new StackPane();
rootPane.setPrefSize(100.0, 100.0);
rootPane.setStyle("-fx-background-color: red");
ContextMenu contextMenu = new ContextMenu();
MenuItem menuItem = new MenuItem("Test Menu Item");
contextMenu.getItems().add(menuItem);
rootPane.setOnContextMenuRequested(event -> {
contextMenu.show(rootPane, event.getScreenX(), event.getScreenY());
System.out.println("Context menu requested");
event.consume();
});
contextMenu.showingProperty().addListener((observable, oldValue, newValue) -> System.out.println("Context menu showing old = " + oldValue + ", new = " + newValue));
Scene scene = new Scene(rootPane);
fxMainPanel.setScene(scene);
}
}