Path: blob/master/test/jdk/java/awt/ComponentOrientation/BorderTest.java
41149 views
/*1* Copyright (c) 1998, 2018, 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* @key headful26* @bug 410845327* @summary Test ComponentOrientation (Bidi) support in BorderLayout28*/29/*30* (C) Copyright IBM Corp. 1998 - All Rights Reserved31*32* The original version of this source code and documentation is copyrighted33* and owned by IBM, Inc. These materials are provided under terms of a34* License Agreement between IBM and Sun. This technology is protected by35* multiple US and International patents. This notice and attribution to IBM36* may not be removed.37*/3839import java.awt.*;40import java.awt.event.*;4142public class BorderTest extends Panel {43Panel panel1;44Panel panel2;4546public BorderTest() {47setLayout(new GridLayout(0,2));4849// Create a panel with a BorderLayout and a bunch of buttons in it50panel1 = new Panel();51panel1.setLayout(new BorderLayout());52panel1.add("North", new Button("North"));53panel1.add("South", new Button("South"));54panel1.add("East", new Button("East"));55panel1.add("West", new Button("West"));56panel1.add("Center", new Button("Center"));57add(panel1);5859// Create a panel with a BorderLayout and a bunch of buttons in it60panel2 = new Panel();61panel2.setLayout(new BorderLayout());62panel2.add(BorderLayout.BEFORE_FIRST_LINE, new Button("FirstLine"));63panel2.add(BorderLayout.AFTER_LAST_LINE, new Button("LastLine"));64panel2.add(BorderLayout.BEFORE_LINE_BEGINS, new Button("FirstItem"));65panel2.add(BorderLayout.AFTER_LINE_ENDS, new Button("LastItem"));66panel2.add("Center", new Button("Center"));67add(panel2);6869// Create a popup menu for switching between orientations70{71Choice c = new Choice();72c.addItem("LEFT_TO_RIGHT");73c.addItem("RIGHT_TO_LEFT");74c.addItem("UNKNOWN");75c.addItemListener( new ItemListener() {76public void itemStateChanged(ItemEvent e) {77String item = (String)(e.getItem());7879ComponentOrientation o = ComponentOrientation.UNKNOWN;80if (item.equals("LEFT_TO_RIGHT")) {81o = ComponentOrientation.LEFT_TO_RIGHT;82} else if (item.equals("RIGHT_TO_LEFT")) {83o = ComponentOrientation.RIGHT_TO_LEFT;84}85panel1.setComponentOrientation(o);86panel2.setComponentOrientation(o);87panel1.layout();88panel2.layout();89panel1.repaint();90panel2.repaint();91}92} );93add(c);94}95}9697public static void main(String args[]) {98Frame f = new Frame("BorderTest");99100f.addWindowListener( new WindowAdapter() {101public void windowClosing(WindowEvent e) {102e.getWindow().hide();103e.getWindow().dispose();104System.exit(0);105};106} );107108BorderTest BorderTest = new BorderTest();109110f.add("Center", BorderTest);111f.setSize(450, 300);112f.show();113}114}115116117