Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JTable/8080972/TestJTableCellEditor.java
41153 views
1
/*
2
* Copyright (c) 2015, 2021, 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
import javax.swing.JTable;
24
import javax.swing.SwingUtilities;
25
import javax.swing.table.AbstractTableModel;
26
import javax.swing.table.TableCellEditor;
27
/*
28
* @test
29
* @bug 8080972
30
* @run main/othervm -Djava.security.manager=allow TestJTableCellEditor
31
32
* @summary Audit Core Reflection in module java.desktop for places that will
33
* require changes to work with modules
34
* @author Alexander Scherbatiy
35
*/
36
37
public class TestJTableCellEditor {
38
39
public static void main(String[] args) throws Exception {
40
SwingUtilities.invokeAndWait(TestJTableCellEditor::testJTableCellEditor);
41
System.setSecurityManager(new SecurityManager());
42
SwingUtilities.invokeAndWait(TestJTableCellEditor::testJTableCellEditor);
43
}
44
45
private static void testJTableCellEditor() {
46
47
final Class cls = UserEditor.class;
48
49
JTable table = new JTable(new AbstractTableModel() {
50
public int getRowCount() {
51
return 0;
52
}
53
54
public int getColumnCount() {
55
return 1;
56
}
57
58
public Object getValueAt(int r, int c) {
59
return "Some Value";
60
}
61
62
public Class getColumnClass(int c) {
63
return cls;
64
}
65
});
66
67
TableCellEditor editor = table.getDefaultEditor(Object.class);
68
editor.getTableCellEditorComponent(table,
69
UserEditor.TEST_VALUE, false, 0, 0);
70
editor.stopCellEditing();
71
Object obj = editor.getCellEditorValue();
72
73
if (obj == null) {
74
throw new RuntimeException("Editor object is null!");
75
}
76
77
if (!UserEditor.TEST_VALUE.equals(((UserEditor) obj).value)) {
78
throw new RuntimeException("Value is incorrect!");
79
}
80
}
81
82
public static class UserEditor {
83
84
private static final String TEST_VALUE = "Test Value";
85
86
private final String value;
87
88
public UserEditor(String value) {
89
this.value = value;
90
}
91
}
92
}
93
94