JDK-8206238 : Aspect ratio is not maintained when Image is scaled in JEditorPane
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 8u192,11
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2018-07-03
  • Updated: 2018-08-02
  • Resolved: 2018-07-12
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 12
11 b23Fixed 12Fixed
Related Reports
Relates :  
Relates :  
Images are not scaled correctly when JEditorPane is used to display HTML content if only width is specified for the image. Height is not scaled as expected to maintain the aspect ratio. A circle of 100x100px and width specified as 200 scaled to an ellipse of height 100 and width 200. It should scaled to a circle with diameter 200.

Use below test program and attached image to reproduce the issue.

import javax.swing.*;

public class ImageTest {
 private static final String ABSOLUTE_FILE_PATH =
 public static void main(String[] args) {
 SwingUtilities.invokeLater(() -> {
 JFrame f = new JFrame();
 // the following line is expected to work in the same
 //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 +
 f.setSize(220, 240);

[~dkumar] If the bug was not fixed completely should we create a new bugid?

[~kaddepalli] please fix this regression in 11