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

JEditorPane unordered list bullets look pixelated

XMLWordPrintable

    • b14
    • x86_64
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      Linux 4.8.0-53-generic #56~16.04.1-Ubuntu SMP Tue May 16 01:18:56 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      When displaying an HTML unordered list in a JEditorPane, the bullets generated by <li> have lower quality: the circular bullets do not look round enough.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the attached example code (TextSample class).
      The upper html is rendered in a default JEditorPane (the issue is reproduced here).
      The lower html is rendered in a JEditorPane configured to use rendering hints to turn on anti-aliasing property KEY_ANTIALIASING (the issue is not reproduced here).

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Default JEditorPane unordered list bullets look round.
      ACTUAL -
      Default JEditorPane unordered list bullets look pixelated.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import java.awt.*;

      public class TextSample {

          private static String getHtml() {
              return "<html><body>" +
                      "<ul>" +
                      "<li>Text</li>" +
                      "</ul>" +
                      "</body></html>";
          }

          private static Component createSplitPane() {
              JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
                      createHtmlViewer(false), createHtmlViewer(true));
              splitPane.setOneTouchExpandable(true);
              splitPane.setResizeWeight(0.5);
              splitPane.setPreferredSize(new Dimension(150, 110));
              return splitPane;
          }

          private static Component createHtmlViewer(boolean antialiasing) {
              JEditorPane editorPane;
              if (antialiasing) {
                  editorPane = new JEditorPane() {
                      @Override
                      public void paint(Graphics g) {
                          Graphics2D g2d = (Graphics2D) g.create();
                          g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                          super.paint(g2d);
                          g2d.dispose();
                      }
                  };
              }
              else {
                  editorPane = new JEditorPane();
              }
              editorPane.setEditable(false);
              editorPane.setContentType("text/html");
              editorPane.setText(getHtml());
              return new JScrollPane(editorPane);
          }

          private static void createAndShowGUI() {
              JFrame frame = new JFrame("List Bullets");
              frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
              frame.add(createSplitPane());
              frame.pack();
              frame.setVisible(true);
          }

          public static void main(String[] args) {
              SwingUtilities.invokeLater(TextSample::createAndShowGUI);
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      As pointed out in https://stackoverflow.com/a/16491992/806803, JEditorPane should use rendering hints to turn on anti-aliasing property KEY_ANTIALIASING.

      FREQUENCY : always


        1. Capture.PNG
          4 kB
          Pardeep Sharma
        2. TextSample.java
          2 kB
          Pardeep Sharma

            psadhukhan Prasanta Sadhukhan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: