-
Bug
-
Resolution: Fixed
-
P4
-
8u20
-
b11
-
x86
-
windows_7
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);
}
});
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);
}
});