Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8195095

Images are not scaled correctly in JEditorPane

    XMLWordPrintable

Details

    Backports

      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

        Attachments

          Issue Links

            Activity

              People

                kaddepalli Krishna Addepalli
                shadowbug Shadow Bug
                Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: