gridbaglayout.html
来自「API資料大全」· HTML 代码 · 共 1,184 行 · 第 1/4 页
HTML
1,184 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd"><!--NewPage--><HTML><HEAD><!-- Generated by javadoc on Thu Apr 27 23:32:41 PDT 2000 --><TITLE>Java 2 Platform SE v1.3: Class GridBagLayout</TITLE><LINK REL ="stylesheet" TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style"></HEAD><BODY BGCOLOR="white"><!-- ========== START OF NAVBAR ========== --><A NAME="navbar_top"><!-- --></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0"><TR><TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"><A NAME="navbar_top_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3"> <TR ALIGN="center" VALIGN="top"> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/GridBagLayout.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../index-files/index-1.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> </TR></TABLE></TD><TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM><b>Java<sup><font size=-2>TM</font></sup> 2 Platform<br>Std. Ed. v1.3</b></EM></TD></TR><TR><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../java/awt/GridBagConstraints.html"><B>PREV CLASS</B></A> <A HREF="../../java/awt/GridLayout.html"><B>NEXT CLASS</B></A></FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../index.html" TARGET="_top"><B>FRAMES</B></A> <A HREF="GridBagLayout.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD></TR><TR><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> SUMMARY: INNER | <A HREF="#field_summary">FIELD</A> | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">DETAIL: <A HREF="#field_detail">FIELD</A> | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD></TR></TABLE><!-- =========== END OF NAVBAR =========== --><HR><!-- ======== START OF CLASS DATA ======== --><H2><FONT SIZE="-1">java.awt</FONT><BR>Class GridBagLayout</H2><PRE><A HREF="../../java/lang/Object.html">java.lang.Object</A> | +--<B>java.awt.GridBagLayout</B></PRE><DL><DT><B>All Implemented Interfaces:</B> <DD><A HREF="../../java/awt/LayoutManager.html">LayoutManager</A>, <A HREF="../../java/awt/LayoutManager2.html">LayoutManager2</A>, <A HREF="../../java/io/Serializable.html">Serializable</A></DD></DL><HR><DL><DT>public class <B>GridBagLayout</B><DT>extends <A HREF="../../java/lang/Object.html">Object</A><DT>implements <A HREF="../../java/awt/LayoutManager2.html">LayoutManager2</A>, <A HREF="../../java/io/Serializable.html">Serializable</A></DL><P>The <code>GridBagLayout</code> class is a flexible layout manager that aligns components vertically and horizontally, without requiring that the components be of the same size. Each <code>GridBagLayout</code> object maintains a dynamic rectangular grid of cells, with each component occupying one or more cells, called its <em>display area</em>. <p> Each component managed by a grid bag layout is associated with an instance of <A HREF="../../java/awt/GridBagConstraints.html"><CODE>GridBagConstraints</CODE></A> that specifies how the component is laid out within its display area. <p> How a <code>GridBagLayout</code> object places a set of components depends on the <code>GridBagConstraints</code> object associated with each component, and on the minimum size and the preferred size of the components' containers. <p> To use a grid bag layout effectively, you must customize one or more of the <code>GridBagConstraints</code> objects that are associated with its components. You customize a <code>GridBagConstraints</code> object by setting one or more of its instance variables: <p> <dl> <dt><A HREF="../../java/awt/GridBagConstraints.html#gridx"><CODE>GridBagConstraints.gridx</CODE></A>, <A HREF="../../java/awt/GridBagConstraints.html#gridy"><CODE>GridBagConstraints.gridy</CODE></A> <dd>Specifies the cell at the upper left of the component's display area, where the upper-left-most cell has address <code>gridx = 0</code>, <code>gridy = 0</code>. Use <code>GridBagConstraints.RELATIVE</code> (the default value) to specify that the component be just placed just to the right of (for <code>gridx</code>) or just below (for <code>gridy</code>) the component that was added to the container just before this component was added. <dt><A HREF="../../java/awt/GridBagConstraints.html#gridwidth"><CODE>GridBagConstraints.gridwidth</CODE></A>, <A HREF="../../java/awt/GridBagConstraints.html#gridheight"><CODE>GridBagConstraints.gridheight</CODE></A> <dd>Specifies the number of cells in a row (for <code>gridwidth</code>) or column (for <code>gridheight</code>) in the component's display area. The default value is 1. Use <code>GridBagConstraints.REMAINDER</code> to specify that the component be the last one in its row (for <code>gridwidth</code>) or column (for <code>gridheight</code>). Use <code>GridBagConstraints.RELATIVE</code> to specify that the component be the next to last one in its row (for <code>gridwidth</code>) or column (for <code>gridheight</code>). <dt><A HREF="../../java/awt/GridBagConstraints.html#fill"><CODE>GridBagConstraints.fill</CODE></A> <dd>Used when the component's display area is larger than the component's requested size to determine whether (and how) to resize the component. Possible values are <code>GridBagConstraints.NONE</code> (the default), <code>GridBagConstraints.HORIZONTAL</code> (make the component wide enough to fill its display area horizontally, but don't change its height), <code>GridBagConstraints.VERTICAL</code> (make the component tall enough to fill its display area vertically, but don't change its width), and <code>GridBagConstraints.BOTH</code> (make the component fill its display area entirely). <dt><A HREF="../../java/awt/GridBagConstraints.html#ipadx"><CODE>GridBagConstraints.ipadx</CODE></A>, <A HREF="../../java/awt/GridBagConstraints.html#ipady"><CODE>GridBagConstraints.ipady</CODE></A> <dd>Specifies the component's internal padding within the layout, how much to add to the minimum size of the component. The width of the component will be at least its minimum width plus <code>(ipadx * 2)</code> pixels (since the padding applies to both sides of the component). Similarly, the height of the component will be at least the minimum height plus <code>(ipady * 2)</code> pixels. <dt><A HREF="../../java/awt/GridBagConstraints.html#insets"><CODE>GridBagConstraints.insets</CODE></A> <dd>Specifies the component's external padding, the minimum amount of space between the component and the edges of its display area. <dt><A HREF="../../java/awt/GridBagConstraints.html#anchor"><CODE>GridBagConstraints.anchor</CODE></A> <dd>Used when the component is smaller than its display area to determine where (within the display area) to place the component. Valid values are <code>GridBagConstraints.CENTER</code> (the default), <code>GridBagConstraints.NORTH</code>, <code>GridBagConstraints.NORTHEAST</code>, <code>GridBagConstraints.EAST</code>, <code>GridBagConstraints.SOUTHEAST</code>, <code>GridBagConstraints.SOUTH</code>, <code>GridBagConstraints.SOUTHWEST</code>, <code>GridBagConstraints.WEST</code>, and <code>GridBagConstraints.NORTHWEST</code>. <dt><A HREF="../../java/awt/GridBagConstraints.html#weightx"><CODE>GridBagConstraints.weightx</CODE></A>, <A HREF="../../java/awt/GridBagConstraints.html#weighty"><CODE>GridBagConstraints.weighty</CODE></A> <dd>Used to determine how to distribute space, which is important for specifying resizing behavior. Unless you specify a weight for at least one component in a row (<code>weightx</code>) and column (<code>weighty</code>), all the components clump together in the center of their container. This is because when the weight is zero (the default), the <code>GridBagLayout</code> object puts any extra space between its grid of cells and the edges of the container. </dl> <p> The following figure shows ten components (all buttons) managed by a grid bag layout: <p> <img src="doc-files/GridBagLayout-1.gif" ALIGN=center HSPACE=10 VSPACE=7> <p> Each of the ten components has the <code>fill</code> field of its associated <code>GridBagConstraints</code> object set to <code>GridBagConstraints.BOTH</code>. In addition, the components have the following non-default constraints: <p> <ul> <li>Button1, Button2, Button3: <code>weightx = 1.0</code> <li>Button4: <code>weightx = 1.0</code>, <code>gridwidth = GridBagConstraints.REMAINDER</code> <li>Button5: <code>gridwidth = GridBagConstraints.REMAINDER</code> <li>Button6: <code>gridwidth = GridBagConstraints.RELATIVE</code> <li>Button7: <code>gridwidth = GridBagConstraints.REMAINDER</code> <li>Button8: <code>gridheight = 2</code>, <code>weighty = 1.0</code> <li>Button9, Button 10: <code>gridwidth = GridBagConstraints.REMAINDER</code> </ul> <p> Here is the code that implements the example shown above: <p> <hr><blockquote><pre> import java.awt.*; import java.util.*; import java.applet.Applet; public class GridBagEx1 extends Applet { protected void makebutton(String name, GridBagLayout gridbag, GridBagConstraints c) { Button button = new Button(name); gridbag.setConstraints(button, c); add(button); } public void init() { GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); setFont(new Font("Helvetica", Font.PLAIN, 14)); setLayout(gridbag); c.fill = GridBagConstraints.BOTH; c.weightx = 1.0; makebutton("Button1", gridbag, c); makebutton("Button2", gridbag, c); makebutton("Button3", gridbag, c); c.gridwidth = GridBagConstraints.REMAINDER; //end row makebutton("Button4", gridbag, c); c.weightx = 0.0; //reset to the default makebutton("Button5", gridbag, c); //another row c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last in row makebutton("Button6", gridbag, c); c.gridwidth = GridBagConstraints.REMAINDER; //end row makebutton("Button7", gridbag, c); c.gridwidth = 1; //reset to the default c.gridheight = 2; c.weighty = 1.0; makebutton("Button8", gridbag, c); c.weighty = 0.0; //reset to the default c.gridwidth = GridBagConstraints.REMAINDER; //end row c.gridheight = 1; //reset to the default makebutton("Button9", gridbag, c); makebutton("Button10", gridbag, c); setSize(300, 100); } public static void main(String args[]) { Frame f = new Frame("GridBag Layout Example"); GridBagEx1 ex1 = new GridBagEx1(); ex1.init(); f.add("Center", ex1); f.pack(); f.setSize(f.getPreferredSize()); f.show(); } } </pre></blockquote><hr> <p><P><DL><DT><B>Since: </B><DD>JDK1.0</DD><DT><B>See Also: </B><DD><A HREF="../../java/awt/GridBagConstraints.html"><CODE>GridBagConstraints</CODE></A>, <A HREF="../../serialized-form.html#java.awt.GridBagLayout">Serialized Form</A></DL><HR><P><!-- ======== INNER CLASS SUMMARY ======== --><!-- =========== FIELD SUMMARY =========== --><A NAME="field_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Field Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> double[]</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/awt/GridBagLayout.html#columnWeights">columnWeights</A></B></CODE><BR> This field holds the overrides to the column weights.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> int[]</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/awt/GridBagLayout.html#columnWidths">columnWidths</A></B></CODE>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?