Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8058704: Nimbus does not honor JTextPane background color #4930

Closed
wants to merge 11 commits into from
@@ -25751,7 +25751,7 @@
<visible>true</visible>
<shapes>
<rectangle x1="0.0" x2="100.0" y1="0.0" y2="30.0" rounding="0.0">
<matte red="255" green="255" blue="255" alpha="255" uiDefaultParentName="nimbusLightBackground" hueOffset="0.0" saturationOffset="0.0" brightnessOffset="0.0" alphaOffset="0"/>
<matte red="255" green="255" blue="255" alpha="255" componentPropertyName="background" uiDefaultParentName="nimbusLightBackground" hueOffset="0.0" saturationOffset="0.0" brightnessOffset="0.0" alphaOffset="0"/>
<paintPoints x1="0.25" y1="0.0" x2="0.2" y2="0.1"/>
</rectangle>
</shapes>
@@ -25857,7 +25857,7 @@
<visible>true</visible>
<shapes>
<rectangle x1="0.0" x2="100.0" y1="0.0" y2="30.0" rounding="0.0">
<matte red="255" green="255" blue="255" alpha="255" uiDefaultParentName="nimbusLightBackground" hueOffset="0.0" saturationOffset="0.0" brightnessOffset="0.0" alphaOffset="0"/>
<matte red="255" green="255" blue="255" alpha="255" componentPropertyName="background" uiDefaultParentName="nimbusLightBackground" hueOffset="0.0" saturationOffset="0.0" brightnessOffset="0.0" alphaOffset="0"/>
<paintPoints x1="0.25" y1="0.0" x2="0.2" y2="0.1"/>
</rectangle>
</shapes>
@@ -0,0 +1,88 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6789980
* @key headful
* @summary Verifies if Nimbus honor JEditorPane background color
* @run main TestNimbusJEditorPaneBgColor
*/
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import javax.swing.JFrame;
import javax.swing.JEditorPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

public class TestNimbusJEditorPaneBgColor {

static JFrame frame;
static volatile Point pt;
static volatile Rectangle bounds;

public static void main(String[] args) throws Exception {
Robot robot = new Robot();
try {
SwingUtilities.invokeAndWait(() -> {
try {
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
} catch (Exception checkedExceptionsPleaseDie) {
throw new RuntimeException(checkedExceptionsPleaseDie);
}
JEditorPane editorPane = new JEditorPane();
editorPane.setContentType("text/plain");
editorPane.setEditable(false);
editorPane.setForeground(Color.GREEN);
editorPane.setBackground(Color.RED);
editorPane.setText("This text should be green on red");

frame = new JFrame();
frame.setDefaultCloseOperation(frame.DISPOSE_ON_CLOSE);
frame.add(editorPane);
frame.setSize(new Dimension(480, 360));
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
robot.waitForIdle();
robot.delay(1000);
SwingUtilities.invokeAndWait(() -> {
pt = frame.getLocationOnScreen();
bounds = frame.getBounds();
});
if (!(robot.getPixelColor(pt.x + bounds.width/2,
pt.y + bounds.height/2)
.equals(Color.RED))) {
throw new RuntimeException("JEditorPane bg Color not same as the color being set");
}
} finally {
SwingUtilities.invokeAndWait(() -> {
if (frame != null) {
frame.dispose();
}
});
}
}
}
@@ -0,0 +1,86 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8058704
* @key headful
* @summary Verifies if Nimbus honor JTextPane background color
* @run main TestNimbusJTextPaneColor
*/
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import javax.swing.JFrame;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

public class TestNimbusJTextPaneColor {

static JFrame frame;
static volatile Point pt;
static volatile Rectangle bounds;

public static void main(String[] args) throws Exception {
Robot robot = new Robot();
try {
SwingUtilities.invokeAndWait(() -> {
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);
This conversation was marked as resolved by prsadhuk

This comment has been minimized.

@prsadhuk

prsadhuk Jul 29, 2021
Author Contributor Outdated

There's a brief flash of white background before the actual and proper background color is set. Since the functionality of JTextPane background is rectified/restored, I have raised the PR and I will work on the initial white flashing in a subsequent PR.

tp.setText("This text should be white on black");

frame = new JFrame();
frame.setDefaultCloseOperation(frame.DISPOSE_ON_CLOSE);
frame.add(tp);
frame.setSize(new Dimension(480, 360));
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
robot.waitForIdle();
robot.delay(1000);
SwingUtilities.invokeAndWait(() -> {
pt = frame.getLocationOnScreen();
bounds = frame.getBounds();
});
if (!(robot.getPixelColor(pt.x + bounds.width/2,
pt.y + bounds.height/2)
.equals(Color.BLACK))) {
throw new RuntimeException("JTextPane Color not same as the color being set");
}
} finally {
SwingUtilities.invokeAndWait(() -> {
if (frame != null) {
frame.dispose();
}
});
}
}
}