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,135 @@
/*
* 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
This conversation was marked as resolved by prsadhuk

This comment has been minimized.

@aivanov-jdk

aivanov-jdk Aug 9, 2021
Member Outdated

…JTextPane and JEditorPane…

* @run main TestNimbusBGColor
*/
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.JEditorPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

public class TestNimbusBGColor {

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

public static void main(String[] args) throws Exception {
robot = new Robot();
testTextPane();
testEditorPane();
}

private static void testTextPane() throws Exception {
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);
tp.setText("This text should be white on black");
This conversation was marked as resolved by prsadhuk
Comment on lines +62 to +65

This comment has been minimized.

@aivanov-jdk

aivanov-jdk Aug 9, 2021
Member Outdated

I meant to pass a component as a parameter to a generic test method.

private static void testComponent(ComponentCreator<? extends JTextComponent> creator) {
        // Set Look and Feel
        JComponent tc = creator.createComponent();
        // set foreground etc and verify
}

I implemented what I had in mind. I don't think it's important what background color you use for each component. The updated test fails without the fix and passes with your fix.


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();
}
});
}
}

private static void testEditorPane() throws Exception {
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();
}
});
}
}
}