Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/Headless/HeadlessJTextArea.java
38840 views
/*1* Copyright (c) 2007, 2014, 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.getPeer();119t.getGraphicsConfiguration();120t.getTreeLock();121t.getToolkit();122t.isValid();123t.isDisplayable();124t.isVisible();125t.isShowing();126t.isEnabled();127t.enable(false);128t.enable(true);129t.enableInputMethods(false);130t.enableInputMethods(true);131t.show();132t.show(false);133t.show(true);134t.hide();135t.getForeground();136t.isForegroundSet();137t.getBackground();138t.isBackgroundSet();139t.getFont();140t.isFontSet();141Container c = new Container();142c.add(t);143t.getLocale();144for (Locale locale : Locale.getAvailableLocales())145t.setLocale(locale);146147t.getColorModel();148t.getLocation();149150boolean exceptions = false;151try {152t.getLocationOnScreen();153} catch (IllegalComponentStateException e) {154exceptions = true;155}156if (!exceptions)157throw new RuntimeException("IllegalComponentStateException did not occur when expected");158159t.location();160t.setLocation(1, 2);161t.move(1, 2);162t.setLocation(new Point(1, 2));163t.getSize();164t.size();165t.setSize(1, 32);166t.resize(1, 32);167t.setSize(new Dimension(1, 32));168t.resize(new Dimension(1, 32));169t.getBounds();170t.bounds();171t.setBounds(10, 10, 10, 10);172t.setBounds(new Rectangle(10, 10, 10, 10));173t.isLightweight();174t.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));175t.getCursor();176t.isCursorSet();177t.inside(1, 2);178t.contains(new Point(1, 2));179t.isFocusable();180t.setFocusable(true);181t.setFocusable(false);182t.transferFocus();183t.getFocusCycleRootAncestor();184t.nextFocus();185t.transferFocusUpCycle();186t.hasFocus();187t.isFocusOwner();188t.toString();189t.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);190t.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);191t.setComponentOrientation(ComponentOrientation.UNKNOWN);192t.getComponentOrientation();193}194}195196197