Path: blob/master/test/jdk/java/beans/XMLEncoder/Test6437265.java
41152 views
/*1* Copyright (c) 2006, 2007, 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/*24* @test25* @bug 643726526* @summary Tests encoding of container with BorderLayout27* @run main/othervm -Djava.security.manager=allow Test643726528* @author Sergey Malenkov29*/3031import java.awt.BorderLayout;32import java.awt.Component;33import javax.swing.JLabel;34import javax.swing.JPanel;3536public final class Test6437265 extends AbstractTest<JPanel> {37private static final String[] NAMES = {38BorderLayout.EAST,39BorderLayout.WEST,40BorderLayout.NORTH,41BorderLayout.SOUTH,42BorderLayout.CENTER,43BorderLayout.LINE_END,44BorderLayout.PAGE_END,45BorderLayout.LINE_START,46BorderLayout.PAGE_START};4748public static void main(String[] args) {49new Test6437265().test(true);50}5152protected JPanel getObject() {53JPanel panel = new MyPanel();54for (String name : NAMES) {55panel.add(name, new JLabel(name));56}57return panel;58}5960protected void validate(JPanel before, JPanel after) {61validate(before);62validate(after);63super.validate(before, after);64}6566private static void validate(JPanel panel) {67BorderLayout layout = (BorderLayout) panel.getLayout();68for (Component component : panel.getComponents()) {69String name = (String) layout.getConstraints(component);70if (name == null)71throw new Error("The component is not layed out: " + component);7273JLabel label = (JLabel) component;74if (!name.equals(label.getText()))75throw new Error("The component is layed out on " + name + ": " + component);76}77}7879public static final class MyPanel extends JPanel {80public MyPanel() {81// the bug is reproducible for containers82// that uses BorderLayout as default layout manager.83super(new BorderLayout(3, 3));84}85}86}878889