Path: blob/master/test/jdk/javax/swing/Headless/HeadlessJTextArea.java
41152 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 java.awt.*;25import java.util.Locale;2627/*28* @test29* @summary Check that JTextArea constructor and methods do not throw unexpected30* exceptions in headless mode31* @run main/othervm -Djava.awt.headless=true HeadlessJTextArea32*/3334public class HeadlessJTextArea {35public static void main(String args[]) {36JTextArea t = new JTextArea();37t.selectAll();38t.getSelectionStart();39t.getSelectionEnd();4041t.getAccessibleContext();42t.isFocusTraversable();43t.setEnabled(false);44t.setEnabled(true);45t.requestFocus();46t.requestFocusInWindow();47t.getPreferredSize();48t.getMaximumSize();49t.getMinimumSize();50t.contains(1, 2);51Component c1 = t.add(new Component(){});52Component c2 = t.add(new Component(){});53Component c3 = t.add(new Component(){});54Insets ins = t.getInsets();55t.getAlignmentY();56t.getAlignmentX();57t.getGraphics();58t.setVisible(false);59t.setVisible(true);60t.setForeground(Color.red);61t.setBackground(Color.red);62for (String font : Toolkit.getDefaultToolkit().getFontList()) {63for (int j = 8; j < 17; j++) {64Font f1 = new Font(font, Font.PLAIN, j);65Font f2 = new Font(font, Font.BOLD, j);66Font f3 = new Font(font, Font.ITALIC, j);67Font f4 = new Font(font, Font.BOLD | Font.ITALIC, j);6869t.setFont(f1);70t.setFont(f2);71t.setFont(f3);72t.setFont(f4);7374t.getFontMetrics(f1);75t.getFontMetrics(f2);76t.getFontMetrics(f3);77t.getFontMetrics(f4);78}79}80t.enable();81t.disable();82t.reshape(10, 10, 10, 10);83t.getBounds(new Rectangle(1, 1, 1, 1));84t.getSize(new Dimension(1, 2));85t.getLocation(new Point(1, 2));86t.getX();87t.getY();88t.getWidth();89t.getHeight();90t.isOpaque();91t.isValidateRoot();92t.isOptimizedDrawingEnabled();93t.isDoubleBuffered();94t.getComponentCount();95t.countComponents();96t.getComponent(1);97t.getComponent(2);98Component[] cs = t.getComponents();99t.getLayout();100t.setLayout(new FlowLayout());101t.doLayout();102t.layout();103t.invalidate();104t.validate();105t.remove(0);106t.remove(c2);107t.removeAll();108t.preferredSize();109t.minimumSize();110t.getComponentAt(1, 2);111t.locate(1, 2);112t.getComponentAt(new Point(1, 2));113t.isFocusCycleRoot(new Container());114t.transferFocusBackward();115t.setName("goober");116t.getName();117t.getParent();118t.getGraphicsConfiguration();119t.getTreeLock();120t.getToolkit();121t.isValid();122t.isDisplayable();123t.isVisible();124t.isShowing();125t.isEnabled();126t.enable(false);127t.enable(true);128t.enableInputMethods(false);129t.enableInputMethods(true);130t.show();131t.show(false);132t.show(true);133t.hide();134t.getForeground();135t.isForegroundSet();136t.getBackground();137t.isBackgroundSet();138t.getFont();139t.isFontSet();140Container c = new Container();141c.add(t);142t.getLocale();143for (Locale locale : Locale.getAvailableLocales())144t.setLocale(locale);145146t.getColorModel();147t.getLocation();148149boolean exceptions = false;150try {151t.getLocationOnScreen();152} catch (IllegalComponentStateException e) {153exceptions = true;154}155if (!exceptions)156throw new RuntimeException("IllegalComponentStateException did not occur when expected");157158t.location();159t.setLocation(1, 2);160t.move(1, 2);161t.setLocation(new Point(1, 2));162t.getSize();163t.size();164t.setSize(1, 32);165t.resize(1, 32);166t.setSize(new Dimension(1, 32));167t.resize(new Dimension(1, 32));168t.getBounds();169t.bounds();170t.setBounds(10, 10, 10, 10);171t.setBounds(new Rectangle(10, 10, 10, 10));172t.isLightweight();173t.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));174t.getCursor();175t.isCursorSet();176t.inside(1, 2);177t.contains(new Point(1, 2));178t.isFocusable();179t.setFocusable(true);180t.setFocusable(false);181t.transferFocus();182t.getFocusCycleRootAncestor();183t.nextFocus();184t.transferFocusUpCycle();185t.hasFocus();186t.isFocusOwner();187t.toString();188t.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);189t.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);190t.setComponentOrientation(ComponentOrientation.UNKNOWN);191t.getComponentOrientation();192}193}194195196