Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/List/FocusEmptyListTest/FocusEmptyListTest.java
38828 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*/2223/*24test25@bug 638727526@summary List: the focus is at the top of the first item, XAWT27@author [email protected] area=awt.list28@run applet FocusEmptyListTest.html29*/3031import java.applet.Applet;32import java.awt.*;33import java.lang.reflect.*;34import java.awt.peer.ListPeer;3536import sun.awt.AWTAccessor;3738public class FocusEmptyListTest extends Applet {3940public void init() {41setLayout(new BorderLayout());42}//End init()4344public void start() {45boolean isXToolkit = Toolkit.getDefaultToolkit()46.getClass().getName().equals("sun.awt.X11.XToolkit");47if (!isXToolkit) {48System.out.println("The test is XAWT-only.");49return;50}5152List list = new List();53Object isIndexDisplayed = null;54setLayout(new FlowLayout());5556getToolkit().addAWTEventListener(System.out::println,57AWTEvent.FOCUS_EVENT_MASK | AWTEvent.WINDOW_FOCUS_EVENT_MASK);5859add(list);60list.add("item1");6162setSize(200, 200);63setVisible(true);64validate();6566list.removeAll();6768try {6970// peer = List.getPeer()71ListPeer peer = (ListPeer)AWTAccessor.getComponentAccessor().getPeer(list);72System.out.println("peer = " + peer);73Class peerClass = peer.getClass();74System.out.println("peer's class = " + peerClass);7576// isIndexDisplayed = peer.isIndexDisplayed(-1)77Method isIndexDisplayedM78= peerClass.getDeclaredMethod("isIndexDisplayed", Integer.TYPE);79System.out.println("method = " + isIndexDisplayedM);80isIndexDisplayedM.setAccessible(true);81isIndexDisplayed = isIndexDisplayedM.invoke(peer, -1);82System.out.println("isIndexDisplayed=" + isIndexDisplayed);8384} catch (Throwable thr) {85throw new RuntimeException("TEST FAILED: " + thr);86}8788if ((Boolean) isIndexDisplayed) {89throw new RuntimeException("TEST FAILED: -1 should be"90+ " invisible index");91}9293}// start()9495}// class AutomaticAppletTest969798