Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/awt/BorderLayout.java
38829 views
/*1* Copyright (c) 1995, 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. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.awt;2627import java.util.Hashtable;2829/**30* A border layout lays out a container, arranging and resizing31* its components to fit in five regions:32* north, south, east, west, and center.33* Each region may contain no more than one component, and34* is identified by a corresponding constant:35* <code>NORTH</code>, <code>SOUTH</code>, <code>EAST</code>,36* <code>WEST</code>, and <code>CENTER</code>. When adding a37* component to a container with a border layout, use one of these38* five constants, for example:39* <pre>40* Panel p = new Panel();41* p.setLayout(new BorderLayout());42* p.add(new Button("Okay"), BorderLayout.SOUTH);43* </pre>44* As a convenience, <code>BorderLayout</code> interprets the45* absence of a string specification the same as the constant46* <code>CENTER</code>:47* <pre>48* Panel p2 = new Panel();49* p2.setLayout(new BorderLayout());50* p2.add(new TextArea()); // Same as p.add(new TextArea(), BorderLayout.CENTER);51* </pre>52* <p>53* In addition, <code>BorderLayout</code> supports the relative54* positioning constants, <code>PAGE_START</code>, <code>PAGE_END</code>,55* <code>LINE_START</code>, and <code>LINE_END</code>.56* In a container whose <code>ComponentOrientation</code> is set to57* <code>ComponentOrientation.LEFT_TO_RIGHT</code>, these constants map to58* <code>NORTH</code>, <code>SOUTH</code>, <code>WEST</code>, and59* <code>EAST</code>, respectively.60* <p>61* For compatibility with previous releases, <code>BorderLayout</code>62* also includes the relative positioning constants <code>BEFORE_FIRST_LINE</code>,63* <code>AFTER_LAST_LINE</code>, <code>BEFORE_LINE_BEGINS</code> and64* <code>AFTER_LINE_ENDS</code>. These are equivalent to65* <code>PAGE_START</code>, <code>PAGE_END</code>, <code>LINE_START</code>66* and <code>LINE_END</code> respectively. For67* consistency with the relative positioning constants used by other68* components, the latter constants are preferred.69* <p>70* Mixing both absolute and relative positioning constants can lead to71* unpredictable results. If72* you use both types, the relative constants will take precedence.73* For example, if you add components using both the <code>NORTH</code>74* and <code>PAGE_START</code> constants in a container whose75* orientation is <code>LEFT_TO_RIGHT</code>, only the76* <code>PAGE_START</code> will be layed out.77* <p>78* NOTE: Currently (in the Java 2 platform v1.2),79* <code>BorderLayout</code> does not support vertical80* orientations. The <code>isVertical</code> setting on the container's81* <code>ComponentOrientation</code> is not respected.82* <p>83* The components are laid out according to their84* preferred sizes and the constraints of the container's size.85* The <code>NORTH</code> and <code>SOUTH</code> components may86* be stretched horizontally; the <code>EAST</code> and87* <code>WEST</code> components may be stretched vertically;88* the <code>CENTER</code> component may stretch both horizontally89* and vertically to fill any space left over.90* <p>91* Here is an example of five buttons in an applet laid out using92* the <code>BorderLayout</code> layout manager:93* <p>94* <img src="doc-files/BorderLayout-1.gif"95* alt="Diagram of an applet demonstrating BorderLayout.96* Each section of the BorderLayout contains a Button corresponding to its position in the layout, one of:97* North, West, Center, East, or South."98* style="float:center; margin: 7px 10px;">99* <p>100* The code for this applet is as follows:101*102* <hr><blockquote><pre>103* import java.awt.*;104* import java.applet.Applet;105*106* public class buttonDir extends Applet {107* public void init() {108* setLayout(new BorderLayout());109* add(new Button("North"), BorderLayout.NORTH);110* add(new Button("South"), BorderLayout.SOUTH);111* add(new Button("East"), BorderLayout.EAST);112* add(new Button("West"), BorderLayout.WEST);113* add(new Button("Center"), BorderLayout.CENTER);114* }115* }116* </pre></blockquote><hr>117* <p>118* @author Arthur van Hoff119* @see java.awt.Container#add(String, Component)120* @see java.awt.ComponentOrientation121* @since JDK1.0122*/123public class BorderLayout implements LayoutManager2,124java.io.Serializable {125/**126* Constructs a border layout with the horizontal gaps127* between components.128* The horizontal gap is specified by <code>hgap</code>.129*130* @see #getHgap()131* @see #setHgap(int)132*133* @serial134*/135int hgap;136137/**138* Constructs a border layout with the vertical gaps139* between components.140* The vertical gap is specified by <code>vgap</code>.141*142* @see #getVgap()143* @see #setVgap(int)144* @serial145*/146int vgap;147148/**149* Constant to specify components location to be the150* north portion of the border layout.151* @serial152* @see #getChild(String, boolean)153* @see #addLayoutComponent154* @see #getLayoutAlignmentX155* @see #getLayoutAlignmentY156* @see #removeLayoutComponent157*/158Component north;159/**160* Constant to specify components location to be the161* west portion of the border layout.162* @serial163* @see #getChild(String, boolean)164* @see #addLayoutComponent165* @see #getLayoutAlignmentX166* @see #getLayoutAlignmentY167* @see #removeLayoutComponent168*/169Component west;170/**171* Constant to specify components location to be the172* east portion of the border layout.173* @serial174* @see #getChild(String, boolean)175* @see #addLayoutComponent176* @see #getLayoutAlignmentX177* @see #getLayoutAlignmentY178* @see #removeLayoutComponent179*/180Component east;181/**182* Constant to specify components location to be the183* south portion of the border layout.184* @serial185* @see #getChild(String, boolean)186* @see #addLayoutComponent187* @see #getLayoutAlignmentX188* @see #getLayoutAlignmentY189* @see #removeLayoutComponent190*/191Component south;192/**193* Constant to specify components location to be the194* center portion of the border layout.195* @serial196* @see #getChild(String, boolean)197* @see #addLayoutComponent198* @see #getLayoutAlignmentX199* @see #getLayoutAlignmentY200* @see #removeLayoutComponent201*/202Component center;203204/**205*206* A relative positioning constant, that can be used instead of207* north, south, east, west or center.208* mixing the two types of constants can lead to unpredictable results. If209* you use both types, the relative constants will take precedence.210* For example, if you add components using both the <code>NORTH</code>211* and <code>BEFORE_FIRST_LINE</code> constants in a container whose212* orientation is <code>LEFT_TO_RIGHT</code>, only the213* <code>BEFORE_FIRST_LINE</code> will be layed out.214* This will be the same for lastLine, firstItem, lastItem.215* @serial216*/217Component firstLine;218/**219* A relative positioning constant, that can be used instead of220* north, south, east, west or center.221* Please read Description for firstLine.222* @serial223*/224Component lastLine;225/**226* A relative positioning constant, that can be used instead of227* north, south, east, west or center.228* Please read Description for firstLine.229* @serial230*/231Component firstItem;232/**233* A relative positioning constant, that can be used instead of234* north, south, east, west or center.235* Please read Description for firstLine.236* @serial237*/238Component lastItem;239240/**241* The north layout constraint (top of container).242*/243public static final String NORTH = "North";244245/**246* The south layout constraint (bottom of container).247*/248public static final String SOUTH = "South";249250/**251* The east layout constraint (right side of container).252*/253public static final String EAST = "East";254255/**256* The west layout constraint (left side of container).257*/258public static final String WEST = "West";259260/**261* The center layout constraint (middle of container).262*/263public static final String CENTER = "Center";264265/**266* Synonym for PAGE_START. Exists for compatibility with previous267* versions. PAGE_START is preferred.268*269* @see #PAGE_START270* @since 1.2271*/272public static final String BEFORE_FIRST_LINE = "First";273274/**275* Synonym for PAGE_END. Exists for compatibility with previous276* versions. PAGE_END is preferred.277*278* @see #PAGE_END279* @since 1.2280*/281public static final String AFTER_LAST_LINE = "Last";282283/**284* Synonym for LINE_START. Exists for compatibility with previous285* versions. LINE_START is preferred.286*287* @see #LINE_START288* @since 1.2289*/290public static final String BEFORE_LINE_BEGINS = "Before";291292/**293* Synonym for LINE_END. Exists for compatibility with previous294* versions. LINE_END is preferred.295*296* @see #LINE_END297* @since 1.2298*/299public static final String AFTER_LINE_ENDS = "After";300301/**302* The component comes before the first line of the layout's content.303* For Western, left-to-right and top-to-bottom orientations, this is304* equivalent to NORTH.305*306* @see java.awt.Component#getComponentOrientation307* @since 1.4308*/309public static final String PAGE_START = BEFORE_FIRST_LINE;310311/**312* The component comes after the last line of the layout's content.313* For Western, left-to-right and top-to-bottom orientations, this is314* equivalent to SOUTH.315*316* @see java.awt.Component#getComponentOrientation317* @since 1.4318*/319public static final String PAGE_END = AFTER_LAST_LINE;320321/**322* The component goes at the beginning of the line direction for the323* layout. For Western, left-to-right and top-to-bottom orientations,324* this is equivalent to WEST.325*326* @see java.awt.Component#getComponentOrientation327* @since 1.4328*/329public static final String LINE_START = BEFORE_LINE_BEGINS;330331/**332* The component goes at the end of the line direction for the333* layout. For Western, left-to-right and top-to-bottom orientations,334* this is equivalent to EAST.335*336* @see java.awt.Component#getComponentOrientation337* @since 1.4338*/339public static final String LINE_END = AFTER_LINE_ENDS;340341/*342* JDK 1.1 serialVersionUID343*/344private static final long serialVersionUID = -8658291919501921765L;345346/**347* Constructs a new border layout with348* no gaps between components.349*/350public BorderLayout() {351this(0, 0);352}353354/**355* Constructs a border layout with the specified gaps356* between components.357* The horizontal gap is specified by <code>hgap</code>358* and the vertical gap is specified by <code>vgap</code>.359* @param hgap the horizontal gap.360* @param vgap the vertical gap.361*/362public BorderLayout(int hgap, int vgap) {363this.hgap = hgap;364this.vgap = vgap;365}366367/**368* Returns the horizontal gap between components.369* @since JDK1.1370*/371public int getHgap() {372return hgap;373}374375/**376* Sets the horizontal gap between components.377* @param hgap the horizontal gap between components378* @since JDK1.1379*/380public void setHgap(int hgap) {381this.hgap = hgap;382}383384/**385* Returns the vertical gap between components.386* @since JDK1.1387*/388public int getVgap() {389return vgap;390}391392/**393* Sets the vertical gap between components.394* @param vgap the vertical gap between components395* @since JDK1.1396*/397public void setVgap(int vgap) {398this.vgap = vgap;399}400401/**402* Adds the specified component to the layout, using the specified403* constraint object. For border layouts, the constraint must be404* one of the following constants: <code>NORTH</code>,405* <code>SOUTH</code>, <code>EAST</code>,406* <code>WEST</code>, or <code>CENTER</code>.407* <p>408* Most applications do not call this method directly. This method409* is called when a component is added to a container using the410* <code>Container.add</code> method with the same argument types.411* @param comp the component to be added.412* @param constraints an object that specifies how and where413* the component is added to the layout.414* @see java.awt.Container#add(java.awt.Component, java.lang.Object)415* @exception IllegalArgumentException if the constraint object is not416* a string, or if it not one of the five specified417* constants.418* @since JDK1.1419*/420public void addLayoutComponent(Component comp, Object constraints) {421synchronized (comp.getTreeLock()) {422if ((constraints == null) || (constraints instanceof String)) {423addLayoutComponent((String)constraints, comp);424} else {425throw new IllegalArgumentException("cannot add to layout: constraint must be a string (or null)");426}427}428}429430/**431* @deprecated replaced by <code>addLayoutComponent(Component, Object)</code>.432*/433@Deprecated434public void addLayoutComponent(String name, Component comp) {435synchronized (comp.getTreeLock()) {436/* Special case: treat null the same as "Center". */437if (name == null) {438name = "Center";439}440441/* Assign the component to one of the known regions of the layout.442*/443if ("Center".equals(name)) {444center = comp;445} else if ("North".equals(name)) {446north = comp;447} else if ("South".equals(name)) {448south = comp;449} else if ("East".equals(name)) {450east = comp;451} else if ("West".equals(name)) {452west = comp;453} else if (BEFORE_FIRST_LINE.equals(name)) {454firstLine = comp;455} else if (AFTER_LAST_LINE.equals(name)) {456lastLine = comp;457} else if (BEFORE_LINE_BEGINS.equals(name)) {458firstItem = comp;459} else if (AFTER_LINE_ENDS.equals(name)) {460lastItem = comp;461} else {462throw new IllegalArgumentException("cannot add to layout: unknown constraint: " + name);463}464}465}466467/**468* Removes the specified component from this border layout. This469* method is called when a container calls its <code>remove</code> or470* <code>removeAll</code> methods. Most applications do not call this471* method directly.472* @param comp the component to be removed.473* @see java.awt.Container#remove(java.awt.Component)474* @see java.awt.Container#removeAll()475*/476public void removeLayoutComponent(Component comp) {477synchronized (comp.getTreeLock()) {478if (comp == center) {479center = null;480} else if (comp == north) {481north = null;482} else if (comp == south) {483south = null;484} else if (comp == east) {485east = null;486} else if (comp == west) {487west = null;488}489if (comp == firstLine) {490firstLine = null;491} else if (comp == lastLine) {492lastLine = null;493} else if (comp == firstItem) {494firstItem = null;495} else if (comp == lastItem) {496lastItem = null;497}498}499}500501/**502* Gets the component that was added using the given constraint503*504* @param constraints the desired constraint, one of <code>CENTER</code>,505* <code>NORTH</code>, <code>SOUTH</code>,506* <code>WEST</code>, <code>EAST</code>,507* <code>PAGE_START</code>, <code>PAGE_END</code>,508* <code>LINE_START</code>, <code>LINE_END</code>509* @return the component at the given location, or <code>null</code> if510* the location is empty511* @exception IllegalArgumentException if the constraint object is512* not one of the nine specified constants513* @see #addLayoutComponent(java.awt.Component, java.lang.Object)514* @since 1.5515*/516public Component getLayoutComponent(Object constraints) {517if (CENTER.equals(constraints)) {518return center;519} else if (NORTH.equals(constraints)) {520return north;521} else if (SOUTH.equals(constraints)) {522return south;523} else if (WEST.equals(constraints)) {524return west;525} else if (EAST.equals(constraints)) {526return east;527} else if (PAGE_START.equals(constraints)) {528return firstLine;529} else if (PAGE_END.equals(constraints)) {530return lastLine;531} else if (LINE_START.equals(constraints)) {532return firstItem;533} else if (LINE_END.equals(constraints)) {534return lastItem;535} else {536throw new IllegalArgumentException("cannot get component: unknown constraint: " + constraints);537}538}539540541/**542* Returns the component that corresponds to the given constraint location543* based on the target <code>Container</code>'s component orientation.544* Components added with the relative constraints <code>PAGE_START</code>,545* <code>PAGE_END</code>, <code>LINE_START</code>, and <code>LINE_END</code>546* take precedence over components added with the explicit constraints547* <code>NORTH</code>, <code>SOUTH</code>, <code>WEST</code>, and <code>EAST</code>.548* The <code>Container</code>'s component orientation is used to determine the location of components549* added with <code>LINE_START</code> and <code>LINE_END</code>.550*551* @param constraints the desired absolute position, one of <code>CENTER</code>,552* <code>NORTH</code>, <code>SOUTH</code>,553* <code>EAST</code>, <code>WEST</code>554* @param target the {@code Container} used to obtain555* the constraint location based on the target556* {@code Container}'s component orientation.557* @return the component at the given location, or <code>null</code> if558* the location is empty559* @exception IllegalArgumentException if the constraint object is560* not one of the five specified constants561* @exception NullPointerException if the target parameter is null562* @see #addLayoutComponent(java.awt.Component, java.lang.Object)563* @since 1.5564*/565public Component getLayoutComponent(Container target, Object constraints) {566boolean ltr = target.getComponentOrientation().isLeftToRight();567Component result = null;568569if (NORTH.equals(constraints)) {570result = (firstLine != null) ? firstLine : north;571} else if (SOUTH.equals(constraints)) {572result = (lastLine != null) ? lastLine : south;573} else if (WEST.equals(constraints)) {574result = ltr ? firstItem : lastItem;575if (result == null) {576result = west;577}578} else if (EAST.equals(constraints)) {579result = ltr ? lastItem : firstItem;580if (result == null) {581result = east;582}583} else if (CENTER.equals(constraints)) {584result = center;585} else {586throw new IllegalArgumentException("cannot get component: invalid constraint: " + constraints);587}588589return result;590}591592593/**594* Gets the constraints for the specified component595*596* @param comp the component to be queried597* @return the constraint for the specified component,598* or null if component is null or is not present599* in this layout600* @see #addLayoutComponent(java.awt.Component, java.lang.Object)601* @since 1.5602*/603public Object getConstraints(Component comp) {604//fix for 6242148 : API method java.awt.BorderLayout.getConstraints(null) should return null605if (comp == null){606return null;607}608if (comp == center) {609return CENTER;610} else if (comp == north) {611return NORTH;612} else if (comp == south) {613return SOUTH;614} else if (comp == west) {615return WEST;616} else if (comp == east) {617return EAST;618} else if (comp == firstLine) {619return PAGE_START;620} else if (comp == lastLine) {621return PAGE_END;622} else if (comp == firstItem) {623return LINE_START;624} else if (comp == lastItem) {625return LINE_END;626}627return null;628}629630/**631* Determines the minimum size of the <code>target</code> container632* using this layout manager.633* <p>634* This method is called when a container calls its635* <code>getMinimumSize</code> method. Most applications do not call636* this method directly.637* @param target the container in which to do the layout.638* @return the minimum dimensions needed to lay out the subcomponents639* of the specified container.640* @see java.awt.Container641* @see java.awt.BorderLayout#preferredLayoutSize642* @see java.awt.Container#getMinimumSize()643*/644public Dimension minimumLayoutSize(Container target) {645synchronized (target.getTreeLock()) {646Dimension dim = new Dimension(0, 0);647648boolean ltr = target.getComponentOrientation().isLeftToRight();649Component c = null;650651if ((c=getChild(EAST,ltr)) != null) {652Dimension d = c.getMinimumSize();653dim.width += d.width + hgap;654dim.height = Math.max(d.height, dim.height);655}656if ((c=getChild(WEST,ltr)) != null) {657Dimension d = c.getMinimumSize();658dim.width += d.width + hgap;659dim.height = Math.max(d.height, dim.height);660}661if ((c=getChild(CENTER,ltr)) != null) {662Dimension d = c.getMinimumSize();663dim.width += d.width;664dim.height = Math.max(d.height, dim.height);665}666if ((c=getChild(NORTH,ltr)) != null) {667Dimension d = c.getMinimumSize();668dim.width = Math.max(d.width, dim.width);669dim.height += d.height + vgap;670}671if ((c=getChild(SOUTH,ltr)) != null) {672Dimension d = c.getMinimumSize();673dim.width = Math.max(d.width, dim.width);674dim.height += d.height + vgap;675}676677Insets insets = target.getInsets();678dim.width += insets.left + insets.right;679dim.height += insets.top + insets.bottom;680681return dim;682}683}684685/**686* Determines the preferred size of the <code>target</code>687* container using this layout manager, based on the components688* in the container.689* <p>690* Most applications do not call this method directly. This method691* is called when a container calls its <code>getPreferredSize</code>692* method.693* @param target the container in which to do the layout.694* @return the preferred dimensions to lay out the subcomponents695* of the specified container.696* @see java.awt.Container697* @see java.awt.BorderLayout#minimumLayoutSize698* @see java.awt.Container#getPreferredSize()699*/700public Dimension preferredLayoutSize(Container target) {701synchronized (target.getTreeLock()) {702Dimension dim = new Dimension(0, 0);703704boolean ltr = target.getComponentOrientation().isLeftToRight();705Component c = null;706707if ((c=getChild(EAST,ltr)) != null) {708Dimension d = c.getPreferredSize();709dim.width += d.width + hgap;710dim.height = Math.max(d.height, dim.height);711}712if ((c=getChild(WEST,ltr)) != null) {713Dimension d = c.getPreferredSize();714dim.width += d.width + hgap;715dim.height = Math.max(d.height, dim.height);716}717if ((c=getChild(CENTER,ltr)) != null) {718Dimension d = c.getPreferredSize();719dim.width += d.width;720dim.height = Math.max(d.height, dim.height);721}722if ((c=getChild(NORTH,ltr)) != null) {723Dimension d = c.getPreferredSize();724dim.width = Math.max(d.width, dim.width);725dim.height += d.height + vgap;726}727if ((c=getChild(SOUTH,ltr)) != null) {728Dimension d = c.getPreferredSize();729dim.width = Math.max(d.width, dim.width);730dim.height += d.height + vgap;731}732733Insets insets = target.getInsets();734dim.width += insets.left + insets.right;735dim.height += insets.top + insets.bottom;736737return dim;738}739}740741/**742* Returns the maximum dimensions for this layout given the components743* in the specified target container.744* @param target the component which needs to be laid out745* @see Container746* @see #minimumLayoutSize747* @see #preferredLayoutSize748*/749public Dimension maximumLayoutSize(Container target) {750return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);751}752753/**754* Returns the alignment along the x axis. This specifies how755* the component would like to be aligned relative to other756* components. The value should be a number between 0 and 1757* where 0 represents alignment along the origin, 1 is aligned758* the furthest away from the origin, 0.5 is centered, etc.759*/760public float getLayoutAlignmentX(Container parent) {761return 0.5f;762}763764/**765* Returns the alignment along the y axis. This specifies how766* the component would like to be aligned relative to other767* components. The value should be a number between 0 and 1768* where 0 represents alignment along the origin, 1 is aligned769* the furthest away from the origin, 0.5 is centered, etc.770*/771public float getLayoutAlignmentY(Container parent) {772return 0.5f;773}774775/**776* Invalidates the layout, indicating that if the layout manager777* has cached information it should be discarded.778*/779public void invalidateLayout(Container target) {780}781782/**783* Lays out the container argument using this border layout.784* <p>785* This method actually reshapes the components in the specified786* container in order to satisfy the constraints of this787* <code>BorderLayout</code> object. The <code>NORTH</code>788* and <code>SOUTH</code> components, if any, are placed at789* the top and bottom of the container, respectively. The790* <code>WEST</code> and <code>EAST</code> components are791* then placed on the left and right, respectively. Finally,792* the <code>CENTER</code> object is placed in any remaining793* space in the middle.794* <p>795* Most applications do not call this method directly. This method796* is called when a container calls its <code>doLayout</code> method.797* @param target the container in which to do the layout.798* @see java.awt.Container799* @see java.awt.Container#doLayout()800*/801public void layoutContainer(Container target) {802synchronized (target.getTreeLock()) {803Insets insets = target.getInsets();804int top = insets.top;805int bottom = target.height - insets.bottom;806int left = insets.left;807int right = target.width - insets.right;808809boolean ltr = target.getComponentOrientation().isLeftToRight();810Component c = null;811812if ((c=getChild(NORTH,ltr)) != null) {813c.setSize(right - left, c.height);814Dimension d = c.getPreferredSize();815c.setBounds(left, top, right - left, d.height);816top += d.height + vgap;817}818if ((c=getChild(SOUTH,ltr)) != null) {819c.setSize(right - left, c.height);820Dimension d = c.getPreferredSize();821c.setBounds(left, bottom - d.height, right - left, d.height);822bottom -= d.height + vgap;823}824if ((c=getChild(EAST,ltr)) != null) {825c.setSize(c.width, bottom - top);826Dimension d = c.getPreferredSize();827c.setBounds(right - d.width, top, d.width, bottom - top);828right -= d.width + hgap;829}830if ((c=getChild(WEST,ltr)) != null) {831c.setSize(c.width, bottom - top);832Dimension d = c.getPreferredSize();833c.setBounds(left, top, d.width, bottom - top);834left += d.width + hgap;835}836if ((c=getChild(CENTER,ltr)) != null) {837c.setBounds(left, top, right - left, bottom - top);838}839}840}841842/**843* Get the component that corresponds to the given constraint location844*845* @param key The desired absolute position,846* either NORTH, SOUTH, EAST, or WEST.847* @param ltr Is the component line direction left-to-right?848*/849private Component getChild(String key, boolean ltr) {850Component result = null;851852if (key == NORTH) {853result = (firstLine != null) ? firstLine : north;854}855else if (key == SOUTH) {856result = (lastLine != null) ? lastLine : south;857}858else if (key == WEST) {859result = ltr ? firstItem : lastItem;860if (result == null) {861result = west;862}863}864else if (key == EAST) {865result = ltr ? lastItem : firstItem;866if (result == null) {867result = east;868}869}870else if (key == CENTER) {871result = center;872}873if (result != null && !result.visible) {874result = null;875}876return result;877}878879/**880* Returns a string representation of the state of this border layout.881* @return a string representation of this border layout.882*/883public String toString() {884return getClass().getName() + "[hgap=" + hgap + ",vgap=" + vgap + "]";885}886}887888889