Hi, here is the reproducer;

OpenJDK version/OS version:
   openjdk 11.0.8 2020-07-14 / Mint Linux 20 
   openjdk 1.8.0_265 / Ubuntu 20.04


import java.awt.*;
import javax.swing.*;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.StyleSheet;

public class Example {

    private String toHex(Color color) {
        return String.format("#%02x%02x%02x", color.getRed(), color.getGreen(), 
color.getBlue());
    }

    public Example() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException | InstantiationException | 
IllegalAccessException | UnsupportedLookAndFeelException e) {
            e.printStackTrace();
        }
        JFrame frame = new JFrame();
        JTextPane pane = new JTextPane();
        pane.setContentType("text/html");
        ((HTMLDocument) pane.getDocument()).setPreservesUnknownTags(false);
        String text = "Displays the text using htmlDocument class <br/>"
                + "font color :  TextPane.foreground=" +  
toHex(UIManager.getColor("TextPane.foreground"))
                + "<br/> background color :  TextPane.background=" + 
toHex(UIManager.getColor("TextPane.background"))
                + "<br/><br/> background color should lighter when light mode 
and darker when dark mode.";
        StyleSheet styleSheet = ((HTMLDocument) 
pane.getDocument()).getStyleSheet();
        styleSheet.addRule("body { font-family: Arial; font-size: 24pt; 
font-style: bold;"
                + " color: " + toHex(UIManager.getColor("TextPane.foreground")) 
+ "; "
                + " background: " + 
toHex(UIManager.getColor("TextPane.background")) + "; "
                + " }");
        pane.setText(text);
        pane.setPreferredSize(new Dimension(800, 200));
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(pane, BorderLayout.CENTER);
        frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        new Example();
    }

}

** Attachment added: "Screencapture on Ubuntu 20.04 with reproducer"
   
https://bugs.launchpad.net/ubuntu/+source/openjdk-lts/+bug/1894419/+attachment/5416409/+files/Screenshot%20from%202020-10-02%2012-43-11.png

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1894419

Title:
  Wrong TextPane.background color with GTKLookAndFeel  on dark theme

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/openjdk-lts/+bug/1894419/+subscriptions

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to