Skip to content

Commit 5dcb7a6

Browse files
author
Abhishek Kumar
committed
8160755: bug6492108.java test fails with exception Image comparison failed at (0, 0) for image 4 in GTK L&F
Reviewed-by: aivanov, dnguyen, tr
1 parent 438121b commit 5dcb7a6

File tree

2 files changed

+149
-4
lines changed

2 files changed

+149
-4
lines changed

src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKStyle.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -747,12 +747,12 @@ public boolean isOpaque(SynthContext context) {
747747
region == Region.TOOL_TIP ||
748748
region == Region.TREE ||
749749
region == Region.VIEWPORT ||
750-
region == Region.TEXT_PANE) {
750+
region == Region.TEXT_PANE ||
751+
region == Region.EDITOR_PANE) {
751752
return true;
752753
}
753754
if (!GTKLookAndFeel.is3()) {
754-
if (region == Region.EDITOR_PANE ||
755-
region == Region.FORMATTED_TEXT_FIELD ||
755+
if (region == Region.FORMATTED_TEXT_FIELD ||
756756
region == Region.PASSWORD_FIELD ||
757757
region == Region.SPINNER ||
758758
region == Region.TEXT_FIELD) {
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/*
2+
* Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
import java.awt.Component;
25+
import java.awt.Container;
26+
import java.awt.Dimension;
27+
import java.awt.GridLayout;
28+
import java.awt.Point;
29+
import java.awt.Rectangle;
30+
import java.awt.image.BufferedImage;
31+
32+
import java.io.File;
33+
import java.io.IOException;
34+
35+
import javax.imageio.ImageIO;
36+
import javax.swing.JEditorPane;
37+
import javax.swing.JPanel;
38+
import javax.swing.JScrollPane;
39+
import javax.swing.JTextArea;
40+
import javax.swing.JTextPane;
41+
import javax.swing.UIManager;
42+
import javax.swing.text.JTextComponent;
43+
44+
import jtreg.SkippedException;
45+
46+
/*
47+
* @test
48+
* @bug 6492108 8160755
49+
* @key headful
50+
* @requires (os.family == "linux")
51+
* @summary Verifies that the background is painted the same for
52+
* JTextArea, JTextPane, and JEditorPane.
53+
* @library /javax/swing/regtesthelpers /test/lib
54+
* @build SwingTestHelper Util
55+
* @run main/othervm bug6492108
56+
*/
57+
58+
public class bug6492108 extends SwingTestHelper {
59+
60+
private JPanel panel;
61+
62+
public static void main(String[] args) throws Throwable {
63+
try {
64+
UIManager.setLookAndFeel(
65+
"com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
66+
} catch (Exception e) {
67+
throw new SkippedException("GTK LAF is not supported on this system");
68+
}
69+
new bug6492108().run(args);
70+
}
71+
72+
private static void addTextComps(Container parent,
73+
Class<? extends JTextComponent> type)
74+
throws Throwable
75+
{
76+
JTextComponent text = type.newInstance();
77+
addTextComp(parent, text);
78+
79+
text = type.newInstance();
80+
text.setEditable(false);
81+
addTextComp(parent, text);
82+
83+
text = type.newInstance();
84+
text.setEnabled(false);
85+
addTextComp(parent, text);
86+
87+
text = type.newInstance();
88+
text.setEnabled(false);
89+
text.setEditable(false);
90+
addTextComp(parent, text);
91+
}
92+
93+
private static void addTextComp(Container parent, JTextComponent text) {
94+
JScrollPane sp = new JScrollPane(text);
95+
text.setFocusable(false); // to avoid showing the blinking caret
96+
sp.setPreferredSize(new Dimension(150, 150));
97+
sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
98+
sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
99+
parent.add(sp);
100+
}
101+
102+
protected Component createContentPane() {
103+
panel = new JPanel();
104+
panel.setLayout(new GridLayout(3, 4));
105+
try {
106+
addTextComps(panel, JTextArea.class);
107+
addTextComps(panel, JEditorPane.class);
108+
addTextComps(panel, JTextPane.class);
109+
} catch (Throwable t) {
110+
fail("Problem creating text components");
111+
}
112+
return panel;
113+
}
114+
115+
private void onEDT10() {
116+
requestAndWaitForFocus(panel);
117+
}
118+
119+
private void onEDT20() {
120+
// For each component on the top row, compare against the two
121+
// components below in the same column. All three components in
122+
// that column should be the same pixel-for-pixel.
123+
for (int count = 0; count < 4; count++) {
124+
Component ref = panel.getComponent(count);
125+
Rectangle refRect = new Rectangle(ref.getLocationOnScreen(), ref.getSize());
126+
BufferedImage refImg = robot.createScreenCapture(refRect);
127+
128+
for (int k = 1; k < 3; k++) {
129+
int index = count + (k*4);
130+
Component test = panel.getComponent(index);
131+
Rectangle testRect = new Rectangle(test.getLocationOnScreen(), test.getSize());
132+
BufferedImage testImg = robot.createScreenCapture(testRect);
133+
134+
if (!Util.compareBufferedImages(refImg, testImg)) {
135+
try {
136+
ImageIO.write(refImg, "png", new File("refImg.png"));
137+
ImageIO.write(testImg, "png", new File("testImg.png"));
138+
} catch (IOException ignored) {}
139+
140+
fail("Image comparison failed for images at index " + count + " and " + index);
141+
}
142+
}
143+
}
144+
}
145+
}

0 commit comments

Comments
 (0)