Skip to content

Commit dc75742

Browse files
committed
8328570: Convert closed JViewport manual applet tests to main
Backport-of: 725d87bbc2abae2ca856d91668f0a494f93fca1c
1 parent 9d1da5b commit dc75742

File tree

5 files changed

+428
-0
lines changed

5 files changed

+428
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Copyright (c) 2001, 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+
/*
25+
* @test
26+
* @bug 4137282
27+
* @summary Tests that scrollbars appear automatically when the enclosed
28+
* component is enlarged
29+
* @library /java/awt/regtesthelpers
30+
* @build PassFailJFrame
31+
* @run main/manual bug4137282
32+
*/
33+
34+
import java.awt.BorderLayout;
35+
import java.awt.Color;
36+
import java.awt.Container;
37+
import java.awt.Dimension;
38+
import javax.swing.JButton;
39+
import javax.swing.JFrame;
40+
import javax.swing.JPanel;
41+
import javax.swing.JScrollPane;
42+
import java.awt.event.ActionEvent;
43+
import java.awt.event.ActionListener;
44+
45+
public class bug4137282 {
46+
47+
private static final String INSTRUCTIONS = """
48+
Press the "resize" button. Two scrollbars should appear.
49+
Press Pass if they appear and Fail otherwise.""";
50+
51+
static volatile JPanel pane;
52+
53+
public static void main(String[] args) throws Exception {
54+
55+
PassFailJFrame.builder()
56+
.title("JViewport Instructions")
57+
.instructions(INSTRUCTIONS)
58+
.rows(5)
59+
.columns(30)
60+
.testUI(bug4137282::createTestUI)
61+
.build()
62+
.awaitAndCheck();
63+
}
64+
65+
private static JFrame createTestUI() {
66+
pane = new JPanel();
67+
68+
pane.setBackground(Color.blue);
69+
setPaneSize(100, 100);
70+
JFrame frame = new JFrame("bug4137282");
71+
JScrollPane sp = new JScrollPane(pane);
72+
73+
JButton b = new JButton("resize");
74+
b.addActionListener(new ActionListener() {
75+
public void actionPerformed(ActionEvent ev) {
76+
setPaneSize(300, 300);
77+
}
78+
});
79+
80+
frame.add(b, BorderLayout.NORTH);
81+
frame.add(sp, BorderLayout.CENTER);
82+
frame.pack();
83+
return frame;
84+
}
85+
86+
static void setPaneSize(int w, int h) {
87+
pane.setPreferredSize(new Dimension(w, h));
88+
pane.setSize(w, h);
89+
}
90+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* Copyright (c) 1999, 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+
/*
25+
* @test
26+
* @bug 4217252
27+
* @summary Tests
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual bug4217252
31+
*/
32+
33+
import java.awt.BorderLayout;
34+
import java.awt.event.ActionEvent;
35+
import java.awt.event.ActionListener;
36+
import java.awt.Rectangle;
37+
import javax.swing.JButton;
38+
import javax.swing.JFrame;
39+
import javax.swing.JScrollPane;
40+
import javax.swing.JTable;
41+
import javax.swing.table.AbstractTableModel;
42+
43+
public class bug4217252 {
44+
45+
private static final String INSTRUCTIONS = """
46+
Click on the 'Scroll' button and then click it again.
47+
If you see row 98 and 99 twice, then test failed, otherwise it passed.""";
48+
49+
static class TestModel extends AbstractTableModel {
50+
51+
public String getColumnName(int column) {
52+
return Integer.toString(column);
53+
}
54+
55+
public int getRowCount() {
56+
return 100;
57+
}
58+
59+
public int getColumnCount() {
60+
return 5;
61+
}
62+
63+
public Object getValueAt(int row, int col) {
64+
return row + " x " + col;
65+
}
66+
67+
public boolean isCellEditable(int row, int column) { return false; }
68+
69+
public void setValueAt(Object value, int row, int col) { }
70+
}
71+
72+
public static void main(String[] args) throws Exception {
73+
74+
PassFailJFrame.builder()
75+
.title("JViewport Instructions")
76+
.instructions(INSTRUCTIONS)
77+
.rows(5)
78+
.columns(30)
79+
.testUI(bug4217252::createTestUI)
80+
.build()
81+
.awaitAndCheck();
82+
}
83+
84+
private static JFrame createTestUI(){
85+
JFrame frame = new JFrame("bug4217252");
86+
final JTable table = new JTable(new TestModel());
87+
JButton scrollButton = new JButton("Scroll");
88+
scrollButton.addActionListener(new ActionListener() {
89+
public void actionPerformed(ActionEvent ae) {
90+
Rectangle bounds = table.getBounds();
91+
bounds.y = bounds.height + table.getRowHeight();
92+
bounds.height = table.getRowHeight();
93+
table.scrollRectToVisible(bounds);
94+
}
95+
});
96+
frame.getContentPane().add(new JScrollPane(table),
97+
BorderLayout.CENTER);
98+
frame.getContentPane().add(scrollButton, BorderLayout.SOUTH);
99+
frame.pack();
100+
return frame;
101+
}
102+
103+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (c) 1999, 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+
/*
25+
* @test
26+
* @bug 4237176
27+
* @summary Tests that background color is set properly for JViewport
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual bug4237176
31+
*/
32+
33+
import java.awt.Color;
34+
import javax.swing.JFrame;
35+
import javax.swing.JScrollPane;
36+
import javax.swing.JTable;
37+
import javax.swing.JViewport;
38+
39+
public class bug4237176 {
40+
41+
private static final String INSTRUCTIONS = """
42+
Look at the empty space below the table. It should be blue.
43+
If it is, test passes, otherwise it fails.""";
44+
45+
public static void main(String[] args) throws Exception {
46+
47+
PassFailJFrame.builder()
48+
.title("JViewport Instructions")
49+
.instructions(INSTRUCTIONS)
50+
.rows(5)
51+
.columns(30)
52+
.testUI(bug4237176::createTestUI)
53+
.build()
54+
.awaitAndCheck();
55+
}
56+
57+
private static JFrame createTestUI() {
58+
JFrame frame = new JFrame("Color Demo");
59+
JTable table = new JTable(new Object[][]{{"one", "two"}}, new Object[]{"A", "B"});
60+
JScrollPane sp = new JScrollPane(table);
61+
JViewport vp = sp.getViewport();
62+
vp.setBackground(Color.blue);
63+
vp.setOpaque(true);
64+
65+
frame.getContentPane().add(sp);
66+
frame.pack();
67+
return frame;
68+
}
69+
70+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* Copyright (c) 1999, 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+
/*
25+
* @test
26+
* @bug 4243479
27+
* @summary Tests that JViewport do not blit when not visible
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual bug4243479
31+
*/
32+
33+
import java.awt.event.ActionEvent;
34+
import java.awt.event.ActionListener;
35+
import java.awt.FlowLayout;
36+
import java.awt.Point;
37+
import javax.swing.JButton;
38+
import javax.swing.JFrame;
39+
import javax.swing.JPanel;
40+
import javax.swing.JScrollPane;
41+
import javax.swing.JTabbedPane;
42+
import javax.swing.JTextArea;
43+
import javax.swing.JViewport;
44+
45+
public class bug4243479 {
46+
private static final String INSTRUCTIONS = """
47+
The tabbed pane contains two tabs: "button" and "scrollpane".
48+
The second contains some text inserted into a scrollpane.
49+
Press the "Press here" button.
50+
If a piece of scrollpane appears, press Fail else press Pass.""";
51+
52+
private static JFrame createTestUI() {
53+
char[] text = new char[20000];
54+
for (int counter = 0; counter < text.length; counter++) {
55+
if (counter % 80 == 0) {
56+
text[counter] = '\n';
57+
}
58+
else {
59+
text[counter] = 'a';
60+
}
61+
}
62+
JScrollPane sp = new JScrollPane(new JTextArea
63+
(new String(text)));
64+
final JViewport vp = sp.getViewport();
65+
vp.putClientProperty("EnableWindowBlit", Boolean.TRUE);
66+
JTabbedPane tp = new JTabbedPane();
67+
JPanel panel = new JPanel(new FlowLayout());
68+
JButton button = new JButton("Press here");
69+
button.addActionListener(new ActionListener() {
70+
public void actionPerformed(ActionEvent ae) {
71+
Point location = vp.getViewPosition();
72+
location.y += 100;
73+
vp.setViewPosition(location);
74+
}
75+
});
76+
panel.add(button);
77+
tp.add("button", panel);
78+
tp.add("scrollpane", sp);
79+
JFrame frame = new JFrame("4243479 Test");
80+
frame.getContentPane().add(tp);
81+
frame.pack();
82+
return frame;
83+
}
84+
85+
public static void main(String[] argv) throws Exception {
86+
PassFailJFrame.builder()
87+
.title("JViewport Instructions")
88+
.instructions(INSTRUCTIONS)
89+
.rows(5)
90+
.columns(30)
91+
.position(PassFailJFrame.Position.TOP_LEFT_CORNER)
92+
.testUI(bug4243479::createTestUI)
93+
.build()
94+
.awaitAndCheck();
95+
}
96+
}

0 commit comments

Comments
 (0)