JDK-8239907 : Vertical White Line appears with JOptionPane.showMessageDialog using a JTextPane/JEditorPane
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 9,11,13,14,15
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2020-02-20
  • Updated: 2022-01-04
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.
Other
tbdUnresolved
Related Reports
Relates :  
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



Comments
The above fix has created several regressions 1) http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/ffe817b77f6a 2) http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/66c4f0fdd33d 3) http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/b8ad62596d8f so it will take more time to investigate the root cause and fix this for good. I will target it at later point of time. Also, I have tried to address this in http://cr.openjdk.java.net/~psadhukhan/8239907/webrev.0/ http://mail.openjdk.java.net/pipermail/swing-dev/2020-July/010513.html but the fix does not tackle all the regression testcases of this fix.
07-10-2020

Seems to be regression from jdk9 b76 onwards due to JDK-8098835
10-03-2020

As per description with JOptionPane.showMessageDialog using a JTextPane (or JEditorPane), an additional vertical white line have started appearing at the right of the dialog box. Checked this for reported version and could confirm the issue. Result: ======== 8u241: OK 9: Fail 11.0.6: Fail 13.0.2: Fail 14 ea b 36: Fail 15 ea b11: Fail This seems a regression in JDK 9 and onward. See attached screenshot as a reference. To check, run the attached test case with respective JDK version.
25-02-2020