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

Nimbus does not honor JTextPane background color

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 8u20
    • Fix Version/s: 18
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b11
    • CPU:
      x86
    • OS:
      windows_7

      Description

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      The Nimbus look and feel ignores the configured background color of a JTextPane and always uses white. Every other look and feel I tested (Metal, Motif, and Windows) correctly honors the configured background color of a JTextPane. Nimbus does correctly honor the other colors of JTextPane, including the foreground color, the selection foreground and selection background colors, and the caret color. Nimbus also correctly honors the background color for the other text components JTextField and JTextArea. It is only the specific combination of Nimbus + JTextPane + backgroundColor that is mysteriously broken.

      In the attached example, a JTextPane is configured to display white-on-black text. Nimbus displays the text white-on-white, so it is completely invisible.


      REPRODUCIBILITY :
      This bug can be reproduced always.

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

      public class NimbusJTextPaneColor {
          public static void main(String[] args) {
              SwingUtilities.invokeLater(() -> {
                  try {
                      UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
                  } catch (Exception checkedExceptionsPleaseDie) {
                      throw new RuntimeException(checkedExceptionsPleaseDie);
                  }
                  
                  JTextPane tp = new JTextPane();
                  tp.setForeground(Color.WHITE);
                  tp.setBackground(Color.BLACK);
                  tp.setText("This text should be white on black");
                  
                  JFrame frame = new JFrame();
                  frame.setDefaultCloseOperation(frame.DISPOSE_ON_CLOSE);
                  frame.add(tp);
                  frame.setSize(new Dimension(480, 360));
                  frame.setVisible(true);
              });
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Run after setting the look and feel:

      UIManager.put("TextPane[Enabled].backgroundPainter", new Painter<JComponent>() {
          @Override
          public void paint(Graphics2D g, JComponent comp, int width, int height) {
              g.setColor(comp.getBackground());
              g.fillRect(0, 0, width, height);
          }
      });

        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:
                Resolved: