Path: blob/master/test/jdk/javax/swing/Headless/HeadlessJTable.java
41149 views
/*1* Copyright (c) 2007, 2015, 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*/2223import javax.swing.*;24import javax.swing.table.AbstractTableModel;25import javax.swing.table.TableModel;26import java.awt.*;27import java.util.Locale;2829/*30* @test31* @summary Check that JTable constructor and methods do not throw unexpected32* exceptions in headless mode33* @run main/othervm -Djava.awt.headless=true HeadlessJTable34*/3536public class HeadlessJTable {37public static void main(String args[]) {38JTable t;39t = new JTable();40final Object[][] data = {41{"cell_1_1", "cell_1_2", "cell_1_3"},42{"cell_2_1", "cell_2_2", "cell_2_3"},43{"cell_3_1", "cell_3_2", "cell_3_3"},44{"cell_4_1", "cell_4_2", "cell_4_3"},45};4647TableModel dataModel = new AbstractTableModel() {48public int getColumnCount() { return 3; }49public int getRowCount() { return data.length;}50public Object getValueAt(int row, int col) {return data[row][col];}51};52t = new JTable(dataModel);5354t.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);55t.getAutoResizeMode();56t.getColumnModel().getColumn(1).setMinWidth(5);57t.getTableHeader().setReorderingAllowed(false);58t.getTableHeader().setResizingAllowed(false);5960t.getAccessibleContext();61t.isFocusTraversable();62t.setEnabled(false);63t.setEnabled(true);64t.requestFocus();65t.requestFocusInWindow();66t.getPreferredSize();67t.getMaximumSize();68t.getMinimumSize();69t.contains(1, 2);70Component c1 = t.add(new Component(){});71Component c2 = t.add(new Component(){});72Component c3 = t.add(new Component(){});73Insets ins = t.getInsets();74t.getAlignmentY();75t.getAlignmentX();76t.getGraphics();77t.setVisible(false);78t.setVisible(true);79t.setForeground(Color.red);80t.setBackground(Color.red);81for (String font : Toolkit.getDefaultToolkit().getFontList()) {82for (int j = 8; j < 17; j++) {83Font f1 = new Font(font, Font.PLAIN, j);84Font f2 = new Font(font, Font.BOLD, j);85Font f3 = new Font(font, Font.ITALIC, j);86Font f4 = new Font(font, Font.BOLD | Font.ITALIC, j);8788t.setFont(f1);89t.setFont(f2);90t.setFont(f3);91t.setFont(f4);9293t.getFontMetrics(f1);94t.getFontMetrics(f2);95t.getFontMetrics(f3);96t.getFontMetrics(f4);97}98}99t.enable();100t.disable();101t.reshape(10, 10, 10, 10);102t.getBounds(new Rectangle(1, 1, 1, 1));103t.getSize(new Dimension(1, 2));104t.getLocation(new Point(1, 2));105t.getX();106t.getY();107t.getWidth();108t.getHeight();109t.isOpaque();110t.isValidateRoot();111t.isOptimizedDrawingEnabled();112t.isDoubleBuffered();113t.getComponentCount();114t.countComponents();115t.getComponent(1);116t.getComponent(2);117Component[] cs = t.getComponents();118t.getLayout();119t.setLayout(new FlowLayout());120t.doLayout();121t.layout();122t.invalidate();123t.validate();124t.remove(0);125t.remove(c2);126t.removeAll();127t.preferredSize();128t.minimumSize();129t.getComponentAt(1, 2);130t.locate(1, 2);131t.getComponentAt(new Point(1, 2));132t.isFocusCycleRoot(new Container());133t.transferFocusBackward();134t.setName("goober");135t.getName();136t.getParent();137t.getGraphicsConfiguration();138t.getTreeLock();139t.getToolkit();140t.isValid();141t.isDisplayable();142t.isVisible();143t.isShowing();144t.isEnabled();145t.enable(false);146t.enable(true);147t.enableInputMethods(false);148t.enableInputMethods(true);149t.show();150t.show(false);151t.show(true);152t.hide();153t.getForeground();154t.isForegroundSet();155t.getBackground();156t.isBackgroundSet();157t.getFont();158t.isFontSet();159Container c = new Container();160c.add(t);161t.getLocale();162for (Locale locale : Locale.getAvailableLocales())163t.setLocale(locale);164165t.getColorModel();166t.getLocation();167168boolean exceptions = false;169try {170t.getLocationOnScreen();171} catch (IllegalComponentStateException e) {172exceptions = true;173}174if (!exceptions)175throw new RuntimeException("IllegalComponentStateException did not occur when expected");176177t.location();178t.setLocation(1, 2);179t.move(1, 2);180t.setLocation(new Point(1, 2));181t.getSize();182t.size();183t.setSize(1, 32);184t.resize(1, 32);185t.setSize(new Dimension(1, 32));186t.resize(new Dimension(1, 32));187t.getBounds();188t.bounds();189t.setBounds(10, 10, 10, 10);190t.setBounds(new Rectangle(10, 10, 10, 10));191t.isLightweight();192t.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));193t.getCursor();194t.isCursorSet();195t.inside(1, 2);196t.contains(new Point(1, 2));197t.isFocusable();198t.setFocusable(true);199t.setFocusable(false);200t.transferFocus();201t.getFocusCycleRootAncestor();202t.nextFocus();203t.transferFocusUpCycle();204t.hasFocus();205t.isFocusOwner();206t.toString();207t.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);208t.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);209t.setComponentOrientation(ComponentOrientation.UNKNOWN);210t.getComponentOrientation();211}212}213214215