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

Aspect ratio is not maintained when Image is scaled in JEditorPane

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b23
    • CPU:
      generic
    • OS:
      generic

      Backports

        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);
         });
        }
        }

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                kaddepalli Krishna Addepalli
                Reporter:
                dkumar Dipak Kumar (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: