Description
ADDITIONAL SYSTEM INFORMATION :
Windows 10 Pro (Version 10.0.17134 Build 17134),
openjdk version "11.0.3-redhat" 2019-04-16 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.3-redhat+7-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.3-redhat+7-LTS, mixed mode)
VM options : --add-modules javafx.base,javafx.graphics,javafx.controls,javafx.web,javafx.media,javafx.swing and a "-p" to directory/directories containing the jars.
Screen resolution: 3840x2160
DPI scaling: 125%
A DESCRIPTION OF THE PROBLEM :
Run the supplied code on a monitor with native resolution 3840x2160 and set to scale (Windows settings) at 125%.
The supplied code uses Robot to try and mimic a user resizing the JFrame. If this does not work (I suspect that the error will manifest at different "resizings" depending on screen resolution and maybe other things), please try and resize the JFrame manually.
The problem is reproducible at 175% scaling too, but at different sizes of the JFrame. The problem is NOT reproducible at 100% or 250% scaling. I have not tried other scaling settings.
Setting the size of the JFrame via code does also NOT show the bug. This makes me believe that the bug is
a rounding error somewhere (you can't set the size of JFrame to a non-integer so I can't test this).
It is possible that the bug happens without JFXPanel but I have not been able to reproduce it without it.
NOTE 1: The supplied code will connect to http://www.google.com as an example site. The problem occurs with any type of content supplied to the WebView (not just google). Just fiddle with the JFrame size manually if the Robot code doesn't show the problem on other sites.
NOTE 2: The bug has nothing to do with the usage of Robot. That part of the code is only there to show the problem without having to tell you exactly how much to resize the JFrame. That is, this problem occurs in our application even though we never use Robot. I can't send you our entire app though so this was the best solution I could think of to show the problem with as little code as possible. I suspect that the error has nothing to do with resize in general, but that either events get lost between Swing and JavaFX or that there is some wonky rounding error when converting sizes/locations between Swing and JavaFX.
Note 3: This is running on RedHat's OpenJDK distribution. It is an OpenJDK or OpenJFX bug though so if you believe this is the cause of the bug, I would be happy to be directed to a place to file bugs against OpenJFX/OpenJDK rather than Oracle's JDK.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the supplied code. Make sure not to move the mouse while Robot is running or the bug will probably only been seen as a flickering.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A straight, non-skewed rendition of http://www.google.com.
ACTUAL -
The rendition is skewed at what seems to be 45 degrees. I would supply a screenshot but not sure how to do that.
---------- BEGIN SOURCE ----------
package your.package.structure;
import java.awt.BorderLayout;
import javafx.application.Platform;
import javafx.concurrent.Worker;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;
import javafx.scene.input.MouseButton;
import javafx.scene.layout.AnchorPane;
import javafx.scene.robot.Robot;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class App {
private final JFrame frame;
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
new App();
});
}
public App() {
frame = new JFrame("Test");
JFXPanel jfx = new JFXPanel();
Platform.runLater(() -> {
jfx.setScene(createScene());
SwingUtilities.invokeLater(() -> {
frame.setLayout(new BorderLayout());
frame.add(jfx, BorderLayout.CENTER);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
});
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public Scene createScene() {
AnchorPane ap = new AnchorPane();
WebView browser = new WebView();
browser.setContextMenuEnabled(false);
WebEngine webkit = browser.getEngine();
webkit.load("http://www.google.com");
webkit.getLoadWorker().stateProperty().addListener((observable, oldValue, newValue) -> {
if(newValue.equals(Worker.State.SUCCEEDED)) {
Platform.runLater(() -> {
Robot rr = new Robot();
double start = frame.getX() + frame.getWidth() - 4;
double end = frame.getX() + frame.getWidth() - 6;
double x = start;
double y = frame.getY() + 100;
rr.mouseMove(x, y);
rr.mousePress(MouseButton.PRIMARY);
for(; x >= end; x = x - 0.05) {
double finalX = x;
Platform.runLater(() -> {
rr.mouseMove(finalX, y);
});
}
Platform.runLater(() -> {
rr.mouseRelease(MouseButton.PRIMARY);
});
});
}
});
AnchorPane.setTopAnchor(browser, 0d);
AnchorPane.setBottomAnchor(browser, 0d);
AnchorPane.setLeftAnchor(browser, 0d);
AnchorPane.setRightAnchor(browser, 0d);
ap.getChildren().add(browser);
Scene scene = new Scene(ap);
return scene;
}
}
---------- END SOURCE ----------
FREQUENCY : always
Windows 10 Pro (Version 10.0.17134 Build 17134),
openjdk version "11.0.3-redhat" 2019-04-16 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.3-redhat+7-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.3-redhat+7-LTS, mixed mode)
VM options : --add-modules javafx.base,javafx.graphics,javafx.controls,javafx.web,javafx.media,javafx.swing and a "-p" to directory/directories containing the jars.
Screen resolution: 3840x2160
DPI scaling: 125%
A DESCRIPTION OF THE PROBLEM :
Run the supplied code on a monitor with native resolution 3840x2160 and set to scale (Windows settings) at 125%.
The supplied code uses Robot to try and mimic a user resizing the JFrame. If this does not work (I suspect that the error will manifest at different "resizings" depending on screen resolution and maybe other things), please try and resize the JFrame manually.
The problem is reproducible at 175% scaling too, but at different sizes of the JFrame. The problem is NOT reproducible at 100% or 250% scaling. I have not tried other scaling settings.
Setting the size of the JFrame via code does also NOT show the bug. This makes me believe that the bug is
a rounding error somewhere (you can't set the size of JFrame to a non-integer so I can't test this).
It is possible that the bug happens without JFXPanel but I have not been able to reproduce it without it.
NOTE 1: The supplied code will connect to http://www.google.com as an example site. The problem occurs with any type of content supplied to the WebView (not just google). Just fiddle with the JFrame size manually if the Robot code doesn't show the problem on other sites.
NOTE 2: The bug has nothing to do with the usage of Robot. That part of the code is only there to show the problem without having to tell you exactly how much to resize the JFrame. That is, this problem occurs in our application even though we never use Robot. I can't send you our entire app though so this was the best solution I could think of to show the problem with as little code as possible. I suspect that the error has nothing to do with resize in general, but that either events get lost between Swing and JavaFX or that there is some wonky rounding error when converting sizes/locations between Swing and JavaFX.
Note 3: This is running on RedHat's OpenJDK distribution. It is an OpenJDK or OpenJFX bug though so if you believe this is the cause of the bug, I would be happy to be directed to a place to file bugs against OpenJFX/OpenJDK rather than Oracle's JDK.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the supplied code. Make sure not to move the mouse while Robot is running or the bug will probably only been seen as a flickering.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A straight, non-skewed rendition of http://www.google.com.
ACTUAL -
The rendition is skewed at what seems to be 45 degrees. I would supply a screenshot but not sure how to do that.
---------- BEGIN SOURCE ----------
package your.package.structure;
import java.awt.BorderLayout;
import javafx.application.Platform;
import javafx.concurrent.Worker;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;
import javafx.scene.input.MouseButton;
import javafx.scene.layout.AnchorPane;
import javafx.scene.robot.Robot;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class App {
private final JFrame frame;
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
new App();
});
}
public App() {
frame = new JFrame("Test");
JFXPanel jfx = new JFXPanel();
Platform.runLater(() -> {
jfx.setScene(createScene());
SwingUtilities.invokeLater(() -> {
frame.setLayout(new BorderLayout());
frame.add(jfx, BorderLayout.CENTER);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
});
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public Scene createScene() {
AnchorPane ap = new AnchorPane();
WebView browser = new WebView();
browser.setContextMenuEnabled(false);
WebEngine webkit = browser.getEngine();
webkit.load("http://www.google.com");
webkit.getLoadWorker().stateProperty().addListener((observable, oldValue, newValue) -> {
if(newValue.equals(Worker.State.SUCCEEDED)) {
Platform.runLater(() -> {
Robot rr = new Robot();
double start = frame.getX() + frame.getWidth() - 4;
double end = frame.getX() + frame.getWidth() - 6;
double x = start;
double y = frame.getY() + 100;
rr.mouseMove(x, y);
rr.mousePress(MouseButton.PRIMARY);
for(; x >= end; x = x - 0.05) {
double finalX = x;
Platform.runLater(() -> {
rr.mouseMove(finalX, y);
});
}
Platform.runLater(() -> {
rr.mouseRelease(MouseButton.PRIMARY);
});
});
}
});
AnchorPane.setTopAnchor(browser, 0d);
AnchorPane.setBottomAnchor(browser, 0d);
AnchorPane.setLeftAnchor(browser, 0d);
AnchorPane.setRightAnchor(browser, 0d);
ap.getChildren().add(browser);
Scene scene = new Scene(ap);
return scene;
}
}
---------- END SOURCE ----------
FREQUENCY : always
Attachments
Issue Links
- duplicates
-
JDK-8220484 JFXPanel renders a slanted image with a hidpi monitor scale of 125% or 175%
- Resolved