Skip to content

Commit b372f28

Browse files
author
Alexander Zvegintsev
committed
8306753: Open source several container AWT tests
Reviewed-by: prr
1 parent e3ccaa6 commit b372f28

4 files changed

+814
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright (c) 2003, 2023, 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 4311614
27+
@summary findComponentAt() should check for isShowing() instead of isVisible()
28+
@key headful
29+
*/
30+
31+
import java.awt.Button;
32+
import java.awt.Component;
33+
import java.awt.EventQueue;
34+
import java.awt.Frame;
35+
import java.awt.Panel;
36+
37+
public class FindComponentAtTest {
38+
public static void main(String[] args) throws Exception {
39+
EventQueue.invokeAndWait(() -> {
40+
Panel aContainer;
41+
Panel bContainer;
42+
Panel cContainer;
43+
Button button = new Button("button4");
44+
Frame frame = new Frame("FindComponentAtTest");
45+
46+
try {
47+
aContainer = new Panel();
48+
bContainer = new Panel();
49+
cContainer = new Panel();
50+
aContainer.setName("ACONT");
51+
bContainer.setName("BCONT");
52+
53+
frame.add(aContainer);
54+
55+
aContainer.add(bContainer);
56+
bContainer.add(cContainer);
57+
cContainer.add(button);
58+
59+
bContainer.setVisible(false);
60+
61+
frame.setSize(200, 200);
62+
frame.setVisible(true);
63+
frame.validate();
64+
65+
System.out.println("Test set for FindComponentAt() method.");
66+
System.out.println("aContainer - visible");
67+
System.out.println("bContainer - child of aContainer - is invisible");
68+
System.out.println("cContainer - child of bContainer - is visible");
69+
System.out.println("button4 - child of cContainer - is visible");
70+
Component comp = cContainer.findComponentAt(
71+
cContainer.getWidth() / 2,
72+
cContainer.getHeight() / 2);
73+
74+
if (comp != null) {
75+
throw new RuntimeException(
76+
"cContainer: Visible component inserted into "
77+
+ "invisible container have found "
78+
+ "by findComponentAt(x, y) method");
79+
}
80+
} finally {
81+
frame.dispose();
82+
}
83+
System.out.println("FindComponentAt Test Succeeded.");
84+
});
85+
}
86+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Copyright (c) 1999, 2023, 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 4196100
27+
@summary Make sure findComponentAt() only returns visible components.
28+
@key headful
29+
*/
30+
31+
import java.awt.BorderLayout;
32+
import java.awt.Color;
33+
import java.awt.Dimension;
34+
import java.awt.EventQueue;
35+
import javax.swing.JFrame;
36+
import javax.swing.JTabbedPane;
37+
import javax.swing.JPanel;
38+
39+
public class FindComponentTest {
40+
41+
public static void main(String[] args) throws Exception {
42+
EventQueue.invokeAndWait(() -> {
43+
FindComponentFrame findComponentAtTest = new FindComponentFrame();
44+
45+
try {
46+
if (!findComponentAtTest.didItWork()) {
47+
throw new RuntimeException(
48+
"findComponentAt() returned non-visible component");
49+
}
50+
} finally {
51+
findComponentAtTest.dispose();
52+
}
53+
});
54+
}
55+
}
56+
57+
58+
class FindComponentFrame extends JFrame {
59+
public FindComponentFrame() {
60+
super("FindComponentFrame");
61+
}
62+
63+
public boolean didItWork() {
64+
setTitle("FindComponentTest");
65+
setSize(new Dimension(200, 200));
66+
67+
JTabbedPane tabbedpane = new JTabbedPane();
68+
setContentPane(tabbedpane);
69+
70+
JPanel panel1 = new JPanel();
71+
panel1.setName("Panel 1");
72+
panel1.setLayout(new BorderLayout());
73+
tabbedpane.add(panel1);
74+
JPanel subPanel = new JPanel();
75+
subPanel.setName("Sub-Panel");
76+
subPanel.setBackground(Color.green);
77+
panel1.add(subPanel); // add sub panel to 1st tab
78+
79+
JPanel panel2 = new JPanel();
80+
panel2.setName("Panel 2");
81+
tabbedpane.add(panel2);
82+
83+
tabbedpane.setSelectedIndex(1); // display 2nd tab
84+
setVisible(true);
85+
86+
boolean success = tabbedpane.findComponentAt(50,50)
87+
.getName().equals("Panel 2");
88+
return success;
89+
}
90+
}

0 commit comments

Comments
 (0)