📄 borderlayout.java
字号:
/* BorderLayout.java -- A layout manager class Copyright (C) 1999, 2002 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception statement from your version. */package java.awt;/** * This class implements a layout manager that positions components * in certain sectors of the parent container. * * @author Aaron M. Renn (arenn@urbanophile.com) * @author Rolf W. Rasmussen <rolfwr@ii.uib.no> */public class BorderLayout implements LayoutManager2, java.io.Serializable{/* * Static Variables *//** * Constant indicating the top of the container */public static final String NORTH = "North";/** * Constant indicating the bottom of the container */public static final String SOUTH = "South";/** * Constant indicating the right side of the container */public static final String EAST = "East";/** * Constant indicating the left side of the container */public static final String WEST = "West";/** * Constant indicating the center of the container */public static final String CENTER = "Center"; /** * The constant indicating the position before the first line of the * layout. The exact position depends on the writing system: For a * top-to-bottom orientation, it is the same as {@link #NORTH}, for * a bottom-to-top orientation, it is the same as {@link #SOUTH}. * * <p>This constant is an older name for {@link #PAGE_START} which * has exactly the same value. * * @since 1.2 */ public static final String BEFORE_FIRST_LINE = "First"; /** * The constant indicating the position after the last line of the * layout. The exact position depends on the writing system: For a * top-to-bottom orientation, it is the same as {@link #SOUTH}, for * a bottom-to-top orientation, it is the same as {@link #NORTH}. * * <p>This constant is an older name for {@link #PAGE_END} which * has exactly the same value. * * @since 1.2 */ public static final String AFTER_LAST_LINE = "Last"; /** * The constant indicating the position before the first item of the * layout. The exact position depends on the writing system: For a * left-to-right orientation, it is the same as {@link #WEST}, for * a right-to-left orientation, it is the same as {@link #EAST}. * * <p>This constant is an older name for {@link #LINE_START} which * has exactly the same value. * * @since 1.2 */ public static final String BEFORE_LINE_BEGINS = "Before"; /** * The constant indicating the position after the last item of the * layout. The exact position depends on the writing system: For a * left-to-right orientation, it is the same as {@link #EAST}, for * a right-to-left orientation, it is the same as {@link #WEST}. * * <p>This constant is an older name for {@link #LINE_END} which * has exactly the same value. * * @since 1.2 */ public static final String AFTER_LINE_ENDS = "After"; /** * The constant indicating the position before the first line of the * layout. The exact position depends on the writing system: For a * top-to-bottom orientation, it is the same as {@link #NORTH}, for * a bottom-to-top orientation, it is the same as {@link #SOUTH}. * * @since 1.4 */ public static final String PAGE_START = BEFORE_FIRST_LINE; /** * The constant indicating the position after the last line of the * layout. The exact position depends on the writing system: For a * top-to-bottom orientation, it is the same as {@link #SOUTH}, for * a bottom-to-top orientation, it is the same as {@link #NORTH}. * * @since 1.4 */ public static final String PAGE_END = AFTER_LAST_LINE; /** * The constant indicating the position before the first item of the * layout. The exact position depends on the writing system: For a * left-to-right orientation, it is the same as {@link #WEST}, for * a right-to-left orientation, it is the same as {@link #EAST}. * * @since 1.4 */ public static final String LINE_START = BEFORE_LINE_BEGINS; /** * The constant indicating the position after the last item of the * layout. The exact position depends on the writing system: For a * left-to-right orientation, it is the same as {@link #EAST}, for * a right-to-left orientation, it is the same as {@link #WEST}. * * @since 1.4 */ public static final String LINE_END = AFTER_LINE_ENDS;// Serialization constantprivate static final long serialVersionUID = -8658291919501921765L;/*************************************************************************//* * Instance Variables *//** * @serial */private Component north;/** * @serial */private Component south;/** * @serial */private Component east;/** * @serial */private Component west;/** * @serial */private Component center;/** * @serial */private Component firstLine;/** * @serial */private Component lastLine;/** * @serial */private Component firstItem;/** * @serial */private Component lastItem;/** * @serial The horizontal gap between components */private int hgap;/** * @serial The vertical gap between components */private int vgap;/*************************************************************************//* * Constructors *//** * Initializes a new instance of <code>BorderLayout</code> with no * horiztonal or vertical gaps between components. */publicBorderLayout(){ this(0,0);}/*************************************************************************//** * Initializes a new instance of <code>BorderLayout</code> with the * specified horiztonal and vertical gaps between components. * * @param hgap The horizontal gap between components. * @param vgap The vertical gap between components. */publicBorderLayout(int hgap, int vgap){ this.hgap = hgap; this.vgap = vgap;}/*************************************************************************//* * Instance Variables *//** * Returns the horitzontal gap value. * * @return The horitzontal gap value. */public intgetHgap(){ return(hgap);}/*************************************************************************//** * Sets the horizontal gap to the specified value. * * @param hgap The new horizontal gap. */public voidsetHgap(int hgap){ this.hgap = hgap;}/*************************************************************************//** * Returns the vertical gap value. * * @return The vertical gap value. */public intgetVgap(){ return(vgap);}/*************************************************************************//** * Sets the vertical gap to the specified value. * * @param vgap The new vertical gap value. */public voidsetVgap(int vgap){ this.vgap = vgap;}/*************************************************************************//** * Adds a component to the layout in the specified constraint position, * which must be one of the string constants defined in this class. * * @param component The component to add. * @param constraints The constraint string. * * @exception IllegalArgumentException If the constraint object is not * a string, or is not one of the specified constants in this class. */public voidaddLayoutComponent(Component component, Object constraints){ if (constraints != null && ! (constraints instanceof String)) throw new IllegalArgumentException("Constraint must be a string"); String str = (String)constraints; if (str == null || str.equals(CENTER)) center = component; else if (str.equals(NORTH)) north = component;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -