JDK-8195095 : Images are not scaled correctly in JEditorPane
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 8u152,9.0.1
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2018-01-15
  • Updated: 2019-02-06
  • Resolved: 2018-03-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 8 Other
11 b07Fixed 8u181Fixed openjdk8u212Fixed
Related Reports
Relates :  
Description
PROBLEM DESCRIPTION

Images are not scaled correctly in JEditorPane
When JEditorPane is used to display HTML content, referenced images are
displayed distorted if only width is specified for the image.
To reproduce the issue, store attached 'circle.png' file somewhere on
file
system, specify path to it in attached ImageTest.java file, compile and
run
it. Expected result - black filled circle is displayed in opened window
(of
approximately 200px diameter). Actual result - black filled ellipse is
displayed (of approximately 200px width and 40px height).
The issue can be reproduced with latest Java 8 (1.8.0_152) and 9 (9.0.1)
builds on Windows 10. I believe, the issue is platform-independent. I'm
not
aware of any previous Java version where this worked correctly.

END PROBLEM DESCRIPTION

Source Code

------------------------------------
ImageTest.java
============
import javax.swing.*;

public class ImageTest {
 private static final String ABSOLUTE_FILE_PATH =
"c:\\ws\\Test\\src\\test\\circle.png";
 
 public static void main(String[] args) {
 SwingUtilities.invokeLater(() -> {
 JFrame f = new JFrame();
 // the following line is expected to work in the same
 //way
 //as the next (commented) line, as the image has aspect ratio 1:1
 JEditorPane editorPane = new JEditorPane("text/html",
"<img width=\"200\" src=\"file:///" + ABSOLUTE_FILE_PATH + "\">");
 // JEditorPane editorPane = new JEditorPane("text/html",
//"<img width=\"200\" height=\"200\" src=\"file:///" + ABSOLUTE_FILE_PATH +
//"\">");
 editorPane.setEditable(false);
 f.add(editorPane);
 f.setSize(220, 240);
 f.setLocationRelativeTo(null);

 f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
 f.setVisible(true);
 });
}
}

End Source

Expected result - black filled circle is displayed in opened window (of
approximately 200px diameter). Actual result - black filled ellipse is
displayed (of approximately 200px width and 40px height).
Workaround
----------
None


Comments
Webrev for 8u-backport - http://cr.openjdk.java.net/~dkumar/8195095/8u_backport/webrev.00/ Patch pushed for JDK 11 doesn’t apply cleanly to JDK 8, mainly because of the line differences and key ‘headful’ has been removed from the test file. Related Jtreg tests have been run against the proposed patch and results are fine.
24-04-2018

URL: http://hg.openjdk.java.net/jdk/jdk/rev/8d8f74e84ff6 User: prr Date: 2018-03-23 17:07:22 +0000
23-03-2018

URL: http://hg.openjdk.java.net/jdk/client/rev/8d8f74e84ff6 User: psadhukhan Date: 2018-03-14 10:16:31 +0000
14-03-2018

Able to reproduce this issue. Checked with Chrome, and W3 Schools site, and they take the actual width/height of the image if the size is not specified, unlike java which is taking a different value.
18-01-2018