Path: blob/master/test/jdk/javax/swing/JSpinner/SpinnerTest.java
41149 views
/*1* Copyright (c) 2020, 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/* @test24@bug 507898925@key headful26@summary Verifies Null Pointer exception is not thrown in SpinnerListMode27@run main SpinnerTest28*/29import javax.swing.JFrame;30import javax.swing.JLabel;31import javax.swing.JPanel;32import javax.swing.JSpinner;33import javax.swing.SpinnerListModel;34import javax.swing.SwingUtilities;35import java.awt.event.KeyEvent;36import java.awt.Point;37import java.awt.Robot;3839public class SpinnerTest40{41private static JFrame frame;42private static JSpinner spinner;4344public static void main(String[] args) throws Exception {45Robot robot = new Robot();46robot.setAutoDelay(100);47try {48SwingUtilities.invokeAndWait(() -> {49//Create and set up the window.50frame = new JFrame("SpinnerDemo");51frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);5253JPanel panel = new JPanel();54String[] values = {"Month: ", "Year: ", null, "Date", "Sent"};5556SpinnerListModel listModel = new SpinnerListModel(values);5758JLabel l = new JLabel("Spinner");59panel.add(l);6061spinner = new JSpinner(listModel);62l.setLabelFor(spinner);63panel.add(spinner);6465panel.setOpaque(true); //content panes must be opaque66frame.setContentPane(panel);6768//Display the window.69frame.pack();70frame.setVisible(true);71frame.setLocationRelativeTo(null);72});73robot.waitForIdle();74robot.delay(1000);75Point loc = spinner.getLocationOnScreen();7677robot.mouseMove(loc.x, loc.y);78robot.keyPress(KeyEvent.VK_SPACE);79robot.keyRelease(KeyEvent.VK_SPACE);8081} finally {82if (frame != null) {83SwingUtilities.invokeAndWait(() -> frame.dispose());84}85}86}87}888990