Path: blob/master/test/jdk/javax/swing/JTable/8080972/TestJTableCellEditor.java
41153 views
/*1* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22import javax.swing.JTable;23import javax.swing.SwingUtilities;24import javax.swing.table.AbstractTableModel;25import javax.swing.table.TableCellEditor;26/*27* @test28* @bug 808097229* @run main/othervm -Djava.security.manager=allow TestJTableCellEditor3031* @summary Audit Core Reflection in module java.desktop for places that will32* require changes to work with modules33* @author Alexander Scherbatiy34*/3536public class TestJTableCellEditor {3738public static void main(String[] args) throws Exception {39SwingUtilities.invokeAndWait(TestJTableCellEditor::testJTableCellEditor);40System.setSecurityManager(new SecurityManager());41SwingUtilities.invokeAndWait(TestJTableCellEditor::testJTableCellEditor);42}4344private static void testJTableCellEditor() {4546final Class cls = UserEditor.class;4748JTable table = new JTable(new AbstractTableModel() {49public int getRowCount() {50return 0;51}5253public int getColumnCount() {54return 1;55}5657public Object getValueAt(int r, int c) {58return "Some Value";59}6061public Class getColumnClass(int c) {62return cls;63}64});6566TableCellEditor editor = table.getDefaultEditor(Object.class);67editor.getTableCellEditorComponent(table,68UserEditor.TEST_VALUE, false, 0, 0);69editor.stopCellEditing();70Object obj = editor.getCellEditorValue();7172if (obj == null) {73throw new RuntimeException("Editor object is null!");74}7576if (!UserEditor.TEST_VALUE.equals(((UserEditor) obj).value)) {77throw new RuntimeException("Value is incorrect!");78}79}8081public static class UserEditor {8283private static final String TEST_VALUE = "Test Value";8485private final String value;8687public UserEditor(String value) {88this.value = value;89}90}91}929394