Skip to content

Commit 9eca53d

Browse files
author
duke
committed
Backport 55afcb57a5d9dbc7bfad75e35df6b96932f6b074
1 parent 23ee787 commit 9eca53d

File tree

3 files changed

+252
-0
lines changed

3 files changed

+252
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 1999, 2025, 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+
/*
25+
* @test
26+
* @bug 4235215
27+
* @summary Tests that Toolkit.getPrintJob() do not throw NPE
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual bug4235215
31+
*/
32+
33+
import java.awt.Toolkit;
34+
import javax.swing.JButton;
35+
import javax.swing.JFrame;
36+
37+
public class bug4235215 {
38+
39+
private static final String INSTRUCTIONS = """
40+
Press "Print Dialog" button.
41+
If you see a print dialog, test passes.
42+
Click "Cancel" button to close it.""";
43+
44+
public static void main(String[] args) throws Exception {
45+
PassFailJFrame.builder()
46+
.title("bug4235215 Instructions")
47+
.instructions(INSTRUCTIONS)
48+
.columns(35)
49+
.testUI(bug4235215::createTestUI)
50+
.build()
51+
.awaitAndCheck();
52+
}
53+
54+
private static JFrame createTestUI() {
55+
JFrame frame = new JFrame("bug4235215");
56+
JButton button = new JButton("Print Dialog");
57+
button.addActionListener(ev -> {
58+
Toolkit.getDefaultToolkit().getPrintJob(frame, "Test Printing", null);
59+
});
60+
frame.add(button);
61+
frame.pack();
62+
return frame;
63+
}
64+
}
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
* Copyright (c) 2000, 2025, 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+
/*
25+
* @test
26+
* @bug 4247610
27+
* @summary Tests an unnecessary repaint issue
28+
* @key headful
29+
* @run main bug4247610
30+
*/
31+
32+
import java.awt.Dimension;
33+
import java.awt.FlowLayout;
34+
import java.awt.Graphics;
35+
import java.awt.Point;
36+
import java.awt.Robot;
37+
import java.awt.event.InputEvent;
38+
import javax.swing.JButton;
39+
import javax.swing.JDesktopPane;
40+
import javax.swing.JFrame;
41+
import javax.swing.JInternalFrame;
42+
import javax.swing.JLabel;
43+
import javax.swing.JPanel;
44+
import javax.swing.SwingUtilities;
45+
46+
import java.util.concurrent.atomic.AtomicInteger;
47+
import java.util.Random;
48+
49+
public class bug4247610 {
50+
51+
private static JFrame frame;
52+
private static JButton damager;
53+
private static volatile Point loc;
54+
private static volatile Dimension size;
55+
private static volatile boolean traced;
56+
private static volatile boolean failed;
57+
58+
public static void main(String[] args) throws Exception {
59+
Robot robot = new Robot();
60+
SwingUtilities.invokeAndWait(() -> {
61+
frame = new JFrame("bug4247610");
62+
JDesktopPane pane = new JDesktopPane();
63+
64+
JInternalFrame jif = new JInternalFrame(
65+
"Damager", true, true, true, true);
66+
InternalFramePanel ifp = new InternalFramePanel();
67+
damager = new JButton("Damage!");
68+
ifp.add(damager);
69+
jif.setContentPane(ifp);
70+
jif.setBounds(0, 0, 300, 300);
71+
jif.setVisible(true);
72+
pane.add(jif);
73+
74+
jif = new JInternalFrame("Damagee", true, true, true, true);
75+
JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
76+
final JLabel damagee = new JLabel("");
77+
panel.add(damagee);
78+
jif.setContentPane(panel);
79+
jif.setBounds(60, 220, 300, 100);
80+
jif.setVisible(true);
81+
pane.add(jif);
82+
83+
final Random random = new Random();
84+
85+
damager.addActionListener((e) -> {
86+
System.out.println("trace paints enabled");
87+
traced = true;
88+
damagee.setText(Integer.toString(random.nextInt()));
89+
});
90+
frame.setContentPane(pane);
91+
frame.setSize(500, 500);
92+
frame.setLocationRelativeTo(null);
93+
frame.setVisible(true);
94+
});
95+
robot.waitForIdle();
96+
robot.delay(1000);
97+
SwingUtilities.invokeAndWait(() -> {
98+
loc = damager.getLocationOnScreen();
99+
size = damager.getSize();
100+
});
101+
robot.mouseMove(loc.x + size.width / 2, loc.y + size.height / 2);
102+
robot.waitForIdle();
103+
robot.delay(200);
104+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
105+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
106+
if (failed) {
107+
throw new RuntimeException("Failed: unnecessary repaint occured");
108+
}
109+
}
110+
111+
112+
static class InternalFramePanel extends JPanel {
113+
final AtomicInteger repaintCounter = new AtomicInteger(0);
114+
InternalFramePanel() {
115+
super(new FlowLayout());
116+
setOpaque(true);
117+
}
118+
119+
public synchronized void paintComponent(Graphics g) {
120+
super.paintComponent(g);
121+
repaintCounter.incrementAndGet();
122+
System.out.println("repaintCounter " + repaintCounter.intValue());
123+
if (traced) {
124+
failed = true;
125+
}
126+
}
127+
}
128+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) 1999, 2025, 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+
/*
25+
* @test
26+
* @bug 4254995
27+
* @summary Tests that html in renderer works correctly
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual bug4254995
31+
*/
32+
33+
import javax.swing.JFrame;
34+
import javax.swing.JList;
35+
import javax.swing.JScrollPane;
36+
37+
public class bug4254995 {
38+
39+
private static final String INSTRUCTIONS = """
40+
If you see a list containing digits from one to seven, test passes.
41+
Otherwise it fails.""";
42+
43+
public static void main(String[] args) throws Exception {
44+
PassFailJFrame.builder()
45+
.title("bug4254995 Instructions")
46+
.instructions(INSTRUCTIONS)
47+
.columns(35)
48+
.testUI(bug4254995::createTestUI)
49+
.build()
50+
.awaitAndCheck();
51+
}
52+
53+
private static JFrame createTestUI() {
54+
JFrame frame = new JFrame("bug4254995");
55+
String[] data = { "1", "2", "3", "4", "<html>5", "6", "7" };
56+
frame.add(new JScrollPane(new JList(data)));
57+
frame.pack();
58+
return frame;
59+
}
60+
}

0 commit comments

Comments
 (0)