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 :  
Description
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.

------------------------------------
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);
 });
}
} 
Comments
[~dkumar] If the bug was not fixed completely should we create a new bugid?
31-07-2018

[~kaddepalli] please fix this regression in 11
05-07-2018