Details
Description
ADDITIONAL SYSTEM INFORMATION :
Windows 10, Java 10 & Java 14
A DESCRIPTION OF THE PROBLEM :
If an EventHandler or EventFilter for a mouse button is attached to a scene within a JFXPanel and the primary mouse button is held, any mouse button click will create an event such that event.getButton().name() wrongly returns PRIMARY, even if the secondary or middle button was clicked.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the code supplied
2. Press and hold the primary button (left button on most machines) on the window
3. While holding the primary button, click the middle or secondary button
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The console should print Button clicked: SECONDARY if the secondary button is clicked while holding the primary button, and should print Button clicked: MIDDLE if the middle button is clicked.
ACTUAL -
The console will print Button clicked: PRIMARY for both buttons.
---------- BEGIN SOURCE ----------
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class Test {
public static void main(String[] args) { SwingUtilities.invokeLater(Test::initAndShowGUI); }
private static void initAndShowGUI() {
// Setup the JFXPanel inside a JPanel
JFrame frame = new JFrame();
final JFXPanel fxPanel = new JFXPanel();
frame.add(fxPanel);
frame.setSize(300, 200);
frame.setVisible(true);
Platform.runLater(() -> initFX(fxPanel));
}
private static void initFX(JFXPanel fxPanel) {
Group root = new Group();
Scene scene = new Scene(root);
// The event handler that incorrectly returns the button held instead of the one clicked
scene.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> System.out.println("Button clicked: " + event.getButton().name()));
fxPanel.setScene(scene);
}
}
---------- END SOURCE ----------
FREQUENCY : always
Windows 10, Java 10 & Java 14
A DESCRIPTION OF THE PROBLEM :
If an EventHandler or EventFilter for a mouse button is attached to a scene within a JFXPanel and the primary mouse button is held, any mouse button click will create an event such that event.getButton().name() wrongly returns PRIMARY, even if the secondary or middle button was clicked.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the code supplied
2. Press and hold the primary button (left button on most machines) on the window
3. While holding the primary button, click the middle or secondary button
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The console should print Button clicked: SECONDARY if the secondary button is clicked while holding the primary button, and should print Button clicked: MIDDLE if the middle button is clicked.
ACTUAL -
The console will print Button clicked: PRIMARY for both buttons.
---------- BEGIN SOURCE ----------
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class Test {
public static void main(String[] args) { SwingUtilities.invokeLater(Test::initAndShowGUI); }
private static void initAndShowGUI() {
// Setup the JFXPanel inside a JPanel
JFrame frame = new JFrame();
final JFXPanel fxPanel = new JFXPanel();
frame.add(fxPanel);
frame.setSize(300, 200);
frame.setVisible(true);
Platform.runLater(() -> initFX(fxPanel));
}
private static void initFX(JFXPanel fxPanel) {
Group root = new Group();
Scene scene = new Scene(root);
// The event handler that incorrectly returns the button held instead of the one clicked
scene.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> System.out.println("Button clicked: " + event.getButton().name()));
fxPanel.setScene(scene);
}
}
---------- END SOURCE ----------
FREQUENCY : always