Skip to content

Commit ba86e9d

Browse files
Andrew LuTheRealMDoerr
authored andcommitted
8307133: Open source some JTable jtreg tests
Backport-of: 5ca0b08a7505d5c210d906e76c2a4cfc3eed64aa
1 parent 026e328 commit ba86e9d

File tree

9 files changed

+486
-0
lines changed

9 files changed

+486
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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 4170447
27+
@summary JTable: non-Icon data in Icon column.
28+
@key headful
29+
*/
30+
31+
import java.io.File;
32+
import java.awt.Component;
33+
import javax.swing.ImageIcon;
34+
import javax.swing.JFrame;
35+
import javax.swing.JScrollPane;
36+
import javax.swing.JTable;
37+
import javax.swing.SwingUtilities;
38+
import javax.swing.table.AbstractTableModel;
39+
import javax.swing.table.TableCellRenderer;
40+
import javax.swing.table.TableModel;
41+
42+
public class bug4170447 {
43+
44+
static volatile boolean failed = false;
45+
static volatile JFrame frame = null;
46+
47+
public static void main(String args[]) throws Exception {
48+
SwingUtilities.invokeAndWait(bug4170447::createUI);
49+
Thread.sleep(5000);
50+
SwingUtilities.invokeAndWait(() -> {
51+
if (frame != null) {
52+
frame.dispose();
53+
}
54+
});
55+
if (failed) {
56+
throw new RuntimeException("Some exception occurred...");
57+
}
58+
}
59+
60+
static void createUI() {
61+
String imgDir = System.getProperty("test.src", ".");
62+
String imgPath = imgDir + File.separator + "swing.small.gif";
63+
ImageIcon icn = new ImageIcon(imgPath,"test");
64+
final Object data[][] = {
65+
{"CELL 0 0", icn},
66+
{"CELL 1 0", "String"}
67+
};
68+
String[] str = {"Column 0", "Column 1"};
69+
70+
TableModel dataModel = new AbstractTableModel() {
71+
public int getColumnCount() { return 2; }
72+
public int getRowCount() { return 2; }
73+
public Object getValueAt(int row, int col) {return data[row][col];}
74+
public Class getColumnClass(int c) {return getValueAt(0, c).getClass();}
75+
public boolean isCellEditable(int row, int col) {return getColumnClass(col) == String.class;}
76+
public void setValueAt(Object aValue, int row, int column) {data[row][column] = aValue;}
77+
};
78+
79+
MyTable tbl = new MyTable(dataModel);
80+
JScrollPane sp = new JScrollPane(tbl);
81+
frame = new JFrame("bug4170447");
82+
frame.getContentPane().add(sp);
83+
frame.pack();
84+
frame.setVisible(true);
85+
}
86+
87+
static class MyTable extends JTable {
88+
public MyTable(TableModel tm) {
89+
super(tm);
90+
}
91+
92+
public Component prepareRenderer(TableCellRenderer rend, int row, int col) {
93+
try {
94+
return super.prepareRenderer(rend, row, col);
95+
} catch (Exception e) {
96+
e.printStackTrace();
97+
failed = true;
98+
return null;
99+
}
100+
}
101+
}
102+
}
Loading
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 4098201
27+
@summary Tests setRowHeight(int row, int height).
28+
*/
29+
30+
import javax.swing.JTable;
31+
32+
public class bug4098201 {
33+
34+
public static void main(String args[]) {
35+
JTable table = new JTable(4,3);
36+
table.setRowHeight(1, table.getRowHeight()*2);
37+
if (table.getRowHeight(0) * 2 != table.getRowHeight(1)) {
38+
throw new Error("Can't set height for specified row...");
39+
}
40+
}
41+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 4130356
27+
@summary JTable.setRowSelectionInterval(int, int) shouldn't accept invalid range
28+
*/
29+
30+
import javax.swing.JTable;
31+
import javax.swing.ListSelectionModel;
32+
33+
public class bug4130356 {
34+
35+
public static void main(String[] argv) {
36+
JTable table = new JTable(4,3);
37+
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
38+
try {
39+
table.setRowSelectionInterval(10,13);
40+
throw new Error("Invalid arguments supported!!!");
41+
} catch (IllegalArgumentException iae) {}
42+
}
43+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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 4159300
27+
@summary Tests that JTable processes tableChanged events quickly
28+
@key headful
29+
*/
30+
31+
import java.awt.BorderLayout;
32+
import java.awt.Container;
33+
import java.awt.Rectangle;
34+
import javax.swing.JButton;
35+
import javax.swing.JFrame;
36+
import javax.swing.JScrollPane;
37+
import javax.swing.JTable;
38+
import javax.swing.SwingUtilities;
39+
import javax.swing.table.DefaultTableModel;
40+
import java.awt.event.ActionEvent;
41+
import java.awt.event.ActionListener;
42+
43+
public class bug4159300 {
44+
45+
static volatile JFrame frame = null;
46+
public static void main(String[] args) throws Exception {
47+
SwingUtilities.invokeAndWait(bug4159300::createUI);
48+
Thread.sleep(3000);
49+
SwingUtilities.invokeAndWait(() -> {
50+
if (frame != null) {
51+
frame.dispose();
52+
}
53+
});
54+
}
55+
56+
static void createUI() {
57+
frame = new JFrame("bug4159300");
58+
Container c = frame.getContentPane();
59+
c.setLayout(new BorderLayout());
60+
// create table
61+
Object[] columnNames = {"only column"};
62+
DefaultTableModel model = new DefaultTableModel(columnNames, 0);
63+
Object[] row = makeRow(model.getRowCount());
64+
model.addRow(row);
65+
66+
JTable table = new JTable(model);
67+
c.add(new JScrollPane(table), BorderLayout.CENTER);
68+
69+
// create button
70+
JButton immediateButton = new JButton("Add row");
71+
immediateButton.addActionListener(new ActionListener() {
72+
public void actionPerformed(ActionEvent e) {
73+
int rowCount = model.getRowCount();
74+
Object[] row = makeRow(rowCount);
75+
model.addRow(row);
76+
int rows = model.getRowCount();
77+
int lastRow = rows - 1;
78+
table.setRowSelectionInterval(lastRow, lastRow);
79+
Rectangle r = table.getCellRect(lastRow, 0, false);
80+
table.scrollRectToVisible(r);
81+
}
82+
});
83+
c.add(immediateButton, BorderLayout.SOUTH);
84+
frame.pack();
85+
frame.setVisible(true);
86+
}
87+
88+
static Object[] makeRow(int rowNumber) {
89+
Object[] row = { ""+rowNumber };
90+
return row;
91+
}
92+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 4243159
27+
@summary Tests that JTable() do not throw ArrayIndexOutOfBoundsException
28+
*/
29+
30+
import javax.swing.JTable;
31+
32+
public class bug4243159 {
33+
34+
/* Looks boring, but tests the no-args constructor works */
35+
public static void main(String[] argv) {
36+
JTable table = new JTable();
37+
}
38+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 4243313
27+
@summary Tests that instantiating JTable through reflection
28+
does not throw ClassNotFoundException
29+
*/
30+
31+
import java.beans.Beans;
32+
33+
public class bug4243313 {
34+
35+
public static void main(String[] argv) throws Exception {
36+
Object table = Beans.instantiate(null, "javax.swing.JTable");
37+
}
38+
}

0 commit comments

Comments
 (0)