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

Vertical White Line appears with JOptionPane.showMessageDialog using a JTextPane/JEditorPane

    Details

    • Subcomponent:
    • Introduced In Version:
      9
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10; Ubuntu 16.04; Ubuntu 18.04
      openjdk version "11.0.6" 2020-01-14
      OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.6+10)
      OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.6+10, mixed mode)


      A DESCRIPTION OF THE PROBLEM :
      Issue with JOptionPane.showMessageDialog using a JTextPane (or JEditorPane).
      An additional vertical white line appears at the right of the dialog box.

      REGRESSION : Last worked in version 8

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See 'Source code for an executable test case'

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Graphical result, the message box without extra white line.
      ACTUAL -
      Ugly message box.

      ---------- BEGIN SOURCE ----------
      import javax.swing.BorderFactory;
      import javax.swing.JOptionPane;
      import javax.swing.JTextPane;
      import javax.swing.SwingUtilities;
      import javax.swing.UIManager;
      import javax.swing.UIManager.LookAndFeelInfo;
      import javax.swing.text.html.HTMLEditorKit;
      import javax.swing.text.html.StyleSheet;

      public class TestMessageBox {

      public static void main(String[] args) {
      try {
      for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
      if ("Nimbus".equals(info.getName())) {
      UIManager.setLookAndFeel(info.getClassName());
      break;
      }
      }

      int color = UIManager.getColor("Panel.background").getRGB() & 0x00FFFFFF;
      final String colorBackground = String.format("#%06x", Integer.valueOf(color));

      JTextPane pane = new JTextPane();
      pane.setContentType("text/html");
      pane.setEditable(false);
      pane.setBorder(BorderFactory.createEmptyBorder());

      HTMLEditorKit htmlEditorKit = (HTMLEditorKit)pane.getEditorKit();
      StyleSheet styleSheet = htmlEditorKit.getStyleSheet();
      styleSheet.addRule("ul{list-style-type: none; margin:4px 0px 12px 20px");
      styleSheet.addRule("body{background-color: " + colorBackground + "; padding: 0px");
      styleSheet.addRule("li{padding:2px;}");

      pane.setText("Riri<br/>Fifi<br/>Loulou");

      SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(null, pane, "Information", JOptionPane.INFORMATION_MESSAGE));
      }
      catch (Exception e) {
      e.printStackTrace();
      }
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      import java.awt.Color;

      import javax.swing.BorderFactory;
      import javax.swing.JOptionPane;
      import javax.swing.JTextPane;
      import javax.swing.SwingUtilities;
      import javax.swing.UIDefaults;
      import javax.swing.UIManager;
      import javax.swing.UIManager.LookAndFeelInfo;
      import javax.swing.plaf.ColorUIResource;
      import javax.swing.text.html.HTMLEditorKit;
      import javax.swing.text.html.StyleSheet;

      public class TestMessageBox3 {

      public static void main(String[] args) {
      try {
      for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
      if ("Nimbus".equals(info.getName())) {
      UIManager.setLookAndFeel(info.getClassName());
      break;
      }
      }

      Color bgColor = UIManager.getColor("Panel.background");

      UIDefaults defaults = new UIDefaults();
      defaults.put("TextPane.background", new ColorUIResource(bgColor));
      defaults.put("TextPane[Enabled].backgroundPainter", bgColor);

      JTextPane pane = new JTextPane();

      pane.setContentType("text/html");
      pane.putClientProperty("Nimbus.Overrides", defaults);
      pane.putClientProperty("Nimbus.Overrides.InheritDefaults", Boolean.TRUE);
      pane.setEditable(false);
      pane.setBorder(BorderFactory.createEmptyBorder());

      HTMLEditorKit htmlEditorKit = (HTMLEditorKit)pane.getEditorKit();
      StyleSheet styleSheet = htmlEditorKit.getStyleSheet();
      styleSheet.addRule("ul{list-style-type: none; margin:4px 0px 12px 20px");
      styleSheet.addRule("body{padding: 0px;}");
      styleSheet.addRule("li{padding:2px;}");

      pane.setText("Riri<br/>Fifi<br/>Loulou");

      SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(null, pane, "Information", JOptionPane.INFORMATION_MESSAGE));
      }
      catch (Exception e) {
      e.printStackTrace();
      }
      }
      }

      FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated: