Path: blob/master/test/jdk/java/awt/Component/InsetsEncapsulation/InsetsEncapsulation.java
41154 views
/*1* Copyright (c) 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 java.awt.Component;24import java.awt.Insets;25import java.util.ArrayList;26import java.util.Collection;2728import javax.swing.Box;29import javax.swing.JButton;30import javax.swing.JCheckBox;31import javax.swing.JCheckBoxMenuItem;32import javax.swing.JColorChooser;33import javax.swing.JComponent;34import javax.swing.JDesktopPane;35import javax.swing.JEditorPane;36import javax.swing.JFileChooser;37import javax.swing.JFormattedTextField;38import javax.swing.JInternalFrame;39import javax.swing.JLabel;40import javax.swing.JLayeredPane;41import javax.swing.JMenu;42import javax.swing.JMenuBar;43import javax.swing.JMenuItem;44import javax.swing.JOptionPane;45import javax.swing.JPasswordField;46import javax.swing.JPopupMenu;47import javax.swing.JProgressBar;48import javax.swing.JRadioButton;49import javax.swing.JRadioButtonMenuItem;50import javax.swing.JRootPane;51import javax.swing.JScrollBar;52import javax.swing.JScrollPane;53import javax.swing.JSeparator;54import javax.swing.JSlider;55import javax.swing.JSpinner;56import javax.swing.JSplitPane;57import javax.swing.JTabbedPane;58import javax.swing.JTable;59import javax.swing.JTextArea;60import javax.swing.JTextField;61import javax.swing.JTextPane;62import javax.swing.JToggleButton;63import javax.swing.JToolBar;64import javax.swing.JTree;65import javax.swing.JViewport;66import javax.swing.SwingUtilities;67import javax.swing.UIManager;68import javax.swing.UnsupportedLookAndFeelException;69import javax.swing.table.JTableHeader;7071import static javax.swing.UIManager.LookAndFeelInfo;72import static javax.swing.UIManager.getInstalledLookAndFeels;7374/**75* @test76* @key headful77* @bug 645980078* @author Sergey Bylokhov79*/80public final class InsetsEncapsulation implements Runnable {8182private final Collection<Component> failures = new ArrayList<>();8384public static void main(final String[] args) throws Exception {85for (final LookAndFeelInfo laf : getInstalledLookAndFeels()) {86SwingUtilities.invokeAndWait(() -> setLookAndFeel(laf));87SwingUtilities.invokeAndWait(new InsetsEncapsulation());88}89}9091@Override92public void run() {93runTest(new JLabel("hi"));94runTest(new JMenu());95runTest(new JTree());96runTest(new JTable());97runTest(new JMenuItem());98runTest(new JCheckBoxMenuItem());99runTest(new JToggleButton());100runTest(new JSpinner());101runTest(new JSlider());102runTest(Box.createVerticalBox());103runTest(Box.createHorizontalBox());104runTest(new JTextField());105runTest(new JTextArea());106runTest(new JTextPane());107runTest(new JPasswordField());108runTest(new JFormattedTextField());109runTest(new JEditorPane());110runTest(new JButton());111runTest(new JColorChooser());112runTest(new JFileChooser());113runTest(new JCheckBox());114runTest(new JInternalFrame());115runTest(new JDesktopPane());116runTest(new JTableHeader());117runTest(new JLayeredPane());118runTest(new JRootPane());119runTest(new JMenuBar());120runTest(new JOptionPane());121runTest(new JRadioButton());122runTest(new JRadioButtonMenuItem());123runTest(new JPopupMenu());124runTest(new JScrollBar());125runTest(new JScrollPane());126runTest(new JViewport());127runTest(new JSplitPane());128runTest(new JTabbedPane());129runTest(new JToolBar());130runTest(new JSeparator());131runTest(new JProgressBar());132if (!failures.isEmpty()) {133System.out.println("These classes failed");134for (final Component failure : failures) {135System.out.println(failure.getClass());136}137throw new RuntimeException("Test failed");138}139}140141void runTest(final JComponent component) {142try {143test(component);144} catch (final Throwable ignored) {145failures.add(component);146}147}148149void test(final JComponent component) {150final Insets p = component.getInsets();151p.top += 3;152if (p.equals(component.getInsets())) {153throw new RuntimeException("Insets altered by altering Insets!");154}155}156157private static void setLookAndFeel(final LookAndFeelInfo laf) {158try {159UIManager.setLookAndFeel(laf.getClassName());160System.out.println("LookAndFeel: " + laf.getClassName());161} catch (ClassNotFoundException | InstantiationException |162UnsupportedLookAndFeelException | IllegalAccessException e) {163throw new RuntimeException(e);164}165}166}167168169