Path: blob/master/test/jdk/javax/swing/JButton/JButtonPaintNPE/JButtonPaintNPE.java
41152 views
/*1* Copyright (c) 2013, 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*/222324import java.awt.Graphics;25import java.awt.Toolkit;26import java.awt.image.BufferedImage;27import java.lang.reflect.InvocationTargetException;2829import javax.swing.JButton;30import javax.swing.JFrame;31import javax.swing.SwingUtilities;3233/**34* @test35* @key headful36* @bug 800991937* @author Sergey Bylokhov38* @library /lib/client/39* @build ExtendedRobot40* @run main JButtonPaintNPE41*/42public final class JButtonPaintNPE {4344private static JFrame frame;4546public static void main(final String[] args)47throws InvocationTargetException, InterruptedException {48SwingUtilities.invokeAndWait(() -> {49frame = new JFrame();50frame.add(new JButton() {51@Override52protected void paintComponent(final Graphics g) {53Graphics gg = new BufferedImage(getWidth(), getHeight(),54BufferedImage.TYPE_INT_ARGB).createGraphics();55super.paintComponent(gg);56gg.dispose();57}58});59frame.setSize(300, 300);60frame.setLocationRelativeTo(null);61frame.setVisible(true);62});63sleep();64SwingUtilities.invokeAndWait(() -> {65if (frame != null) {66frame.dispose();67}68});69}7071private static void sleep() {72try {73ExtendedRobot robot = new ExtendedRobot();74robot.waitForIdle(1000);75}catch(Exception ex) {76ex.printStackTrace();77throw new Error("Unexpected Failure");78}79}80}818283