Why IntelliJ IDEA 2020.1 doesn't properly render HTML content font color in Dracula theme for JTextPane?

Answered

I'm working on an IntelliJ IDEA plugin which contains JTextPane and I'm using HTML to render hyperlink alone with some other text. But in 2020.1 version when I change the theme to Dracula the rest of the text color changed to black. But for the older version, it worked fine.

IntelliJ IDEA 2020.1 

 

IntelliJ IDEA 2019.2

 

Sample Code: 

 

JTextPane textWithHyperlink = new JTextPane();
textWithHyperlink.setPreferredSize(new Dimension(600, 50));
textWithHyperlink.setEditable(false);
textWithHyperlink.setContentType("text/html")
textWithHyperlink.setText("<html>This is sample text and <a href=\"http://www.google.com\">This is a Link</a></html>");

 

Please let me know what's needs to be changed? 

 

 

0
7 comments

Thusitha,

That change was introduced in 2019.3.

As a solution, you can provide additional CSS styles together with your HTML code, like:

textWithHyperlink.setText("<html><style>a { color: red }</style> This is sample ...</html>");
0

Hi Jakub,

Thanks a lot for your response and it works. But the issue that I'm facing is not quite the same. What I'm expecting is, in previous IntelliJ versions when I changed the themes from "IntelliJ Light" to "Dracula" and vice-versa font color changed to invert color. But in 2020.1 version it doesn't change for "Dracula" and "High Contrast themes" and this only affects JTextPane component. Please check the below screenshots.  

 

IntelliJ IDEA 2019.2 - IntelliJ Theme

IntelliJ IDEA 2019.2 - Dracula Theme

 

IntelliJ IDEA 2020.1 - IntelliJ Light Theme

 

IntelliJ IDEA 2020.1 - Dracula Theme

 

Yes, I could solve this issue programmatically using your suggestion but then I need to add a condition for each theme. But it would be better if it can handle by the IDE. Please let me know your thoughts.

 

0

Just a side question - after applying the dark theme, did you restarted the IDE?

I've checked your code snippet and I can see that colours look good:

0

Hmm Yes, I restarted the IDE but the same result.

0

I've encountered this problem in IDE version > 2020.1 as well with a plugin I worked on. I'm not sure what happened across versions of the IDE, but I've had some luck playing around with the custom fonts to get the fonts to invert the color based on the selected theme:

Try disabling the 'Use custom font' option in Preferences -> Appearance section and then restart the IDE. I tried this and once I restarted the IDE the font color inside of my plugin's JTextPane inverted properly. I was then able to reselect the custom font that I was using and restart the IDE again and it maintained the inverted font color. This should not require any programmatic changes to your plugin. Hopefully that will work for you.

0

Facing same issue with JEditorPane in 2020.3. Have not checked the previous releases.

 

I am still working on the plugin and seeing some discrepancies in different themes.

For example:

1. In Darcula, the text does not change from black and hence not legible

2. When changing to IntelliJ Light theme, the font color is correct but somehow it loses the html tags and shows as plain text.

0

I am facing the same issue. in a configuration setting page I have created with 2020.3. I have JLabels and JTextPanes, with the same theme and same settings JTextpanes are black and JLabels are white on Darcula which shouldn't be considered as a feature I believe. It really looks ugly. 

0

Please sign in to leave a comment.