鍍金池/ 教程/ Java/ Swing GridBagLayout布局類
Swing JRadioButton
Swing Layout布局
Swing JTextField
Swing JLabel
Swing開發(fā)環(huán)境安裝
Swing JComponent類
SWING ActionEvent事件類
Swing JScrollBar
Swing教程首頁
Swing JFileChooser
SWING ContainerEvent事件處理類
Swing AdjustmentListener接口
Swing WindowAdapter類
SWING ComponentListener接口
Swing JMenuBar類
Swing JPanel類及實(shí)例
Swing
SWING AdjustmentEvent事件處理
Swing JWindow類及實(shí)例
Swing介紹
Swing MouseMotionAdapter類
SWING WindowEvent事件類
Swing ItemListener接口
SWING MouseEvent事件類
Swing JMenu類
SWING KeyEvent事件類
Swing MouseMotionListener接口
Swing JProgressBar
SWING AWTEvent事件類
Swing JRadioButtonMenuItem類及例子
Swing KeyAdapter類
SWING ActionListener接口
Swing LayoutManager接口
SWING MouseMotionEvent事件處理
Swing Component類
Swing Container類
Swing CardLayout布局
Swing MouseAdapter類
Swing JSlider
Swing KeyListener接口
Swing FocusAdapter類
Swing JColorChooser
Swing ImageIcon
Swing JComboBox
Swing GroupLayout布局類
Swing JOptionPane
Swing GridBagLayout布局類
Swing JMenuItem類
Swing MouseListener Interface
Swing事件適配器
SWING ComponentEvent處理類
SWING PaintEvent事件類
Swing FlowLayout布局類
SWING Event事件類
Swing FocusListener接口
Swing控件
Swing JButton
Swing JCheckBox
Swing SpringLayout布局類
Swing容器
Swing事件處理
Swing事件監(jiān)聽器
Swing Menu菜單類
Swing JList
Swing ContainerListener接口
Swing LayoutManager2接口
Swing JFrame類和實(shí)例
Swing JTextArea
SWING InputEvent事件類
Swing BorderLayout布局
Swing WindowListener接口
Swing JCheckboxMenuItem類及例子
Swing JSpinner
Swing GridLayout布局類
Swing JPopupMenu類及實(shí)例

Swing GridBagLayout布局類

GridBagLayout類將組件排列在一個(gè)水平和垂直的方式。

類聲明

以下是聲明 java.awt.GridBagLayout類:

public class GridBagLayout
   extends Object
      implements LayoutManager2, Serializable

字段域

以下是 java.awt.GridBagLayout類的字段域:

  • static int DEFAULT_SIZE --表示組件或間隙的大小應(yīng)該用于特定的范圍值。

  • static int PREFERRED_SIZE -- 表示組件或間隙的首選大小應(yīng)該用于特定的范圍值。

類構(gòu)造函數(shù)

S.N. 構(gòu)造函數(shù) & 描述
1 GridBagLayout()
Creates a grid bag layout manager.

類方法

S.N. 方法 & 描述
1 void addLayoutComponent(Component comp, Object constraints) 
Adds the specified component to the layout, using the specified constraints object.
2 void addLayoutComponent(String name, Component comp) 
Adds the specified component with the specified name to the layout.
3 protected void adjustForGravity(GridBagConstraints constraints, Rectangle r) 
Adjusts the x, y, width, and height fields to the correct values depending on the constraint geometry and pads.
4 protected void AdjustForGravity(GridBagConstraints constraints, Rectangle r) 
This method is obsolete and supplied for backwards compatability only; new code should call adjustForGravity instead.
5 protected void arrangeGrid(Container parent) 
Lays out the grid.
6 protected void ArrangeGrid(Container parent) 
This method is obsolete and supplied for backwards compatability only; new code should call arrangeGrid instead.
7 GridBagConstraints getConstraints(Component comp) 
Gets the constraints for the specified component.
8 float getLayoutAlignmentX(Container parent) 
Returns the alignment along the x axis.
9 float getLayoutAlignmentY(Container parent) 
Returns the alignment along the y axis.
10 int[][] getLayoutDimensions() 
Determines column widths and row heights for the layout grid.
11 protected java.awt.GridBagLayoutInfo getLayoutInfo(Container parent, int sizeflag) 
Fills in an instance of GridBagLayoutInfo for the current set of managed children.
12 protected java.awt.GridBagLayoutInfo GetLayoutInfo(Container parent, int sizeflag) 
This method is obsolete and supplied for backwards compatability only; new code should call getLayoutInfo instead.
13 Point getLayoutOrigin() 
Determines the origin of the layout area, in the graphics coordinate space of the target container.
14 double[][] getLayoutWeights() 
Determines the weights of the layout grid's columns and rows.
15 protected Dimension getMinSize(Container parent, java.awt.GridBagLayoutInfo info) 
Figures out the minimum size of the master based on the information from getLayoutInfo().
16 protected Dimension GetMinSize(Container parent, java.awt.GridBagLayoutInfo info) 
This method is obsolete and supplied for backwards compatability only; new code should call getMinSize instead.
17 void invalidateLayout(Container target) 
Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.
18 void layoutContainer(Container parent) 
Lays out the specified container using this grid bag layout.
19 Point location(int x, int y) 
Determines which cell in the layout grid contains the point specified by (x, y).
20 protected GridBagConstraints lookupConstraints(Component comp) 
Retrieves the constraints for the specified component.
21 Dimension maximumLayoutSize(Container target) 
Returns the maximum dimensions for this layout given the components in the specified target container.
22 Dimension minimumLayoutSize(Container parent) 
Determines the minimum size of the parent container using this grid bag layout.
23 Dimension preferredLayoutSize(Container parent) 
Determines the preferred size of the parent container using this grid bag layout.
24 void removeLayoutComponent(Component comp) 
Removes the specified component from this layout.
25 void setConstraints(Component comp, GridBagConstraints constraints) 
Sets the constraints for the specified component in this layout.
26 String toString() 
Returns a string representation of this grid bag layout's values.

方法繼承

這個(gè)類從以下類繼承的方法:

  • java.lang.Object

GridBagLayout Example

選擇使用任何編輯器創(chuàng)建以下java程序在 D:/ > SWING > com > yiibai > gui >

SwingLayoutDemo.java
package com.yiibai.gui;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class SwingLayoutDemo {
   private JFrame mainFrame;
   private JLabel headerLabel;
   private JLabel statusLabel;
   private JPanel controlPanel;
   private JLabel msglabel;

   public SwingLayoutDemo(){
      prepareGUI();
   }

   public static void main(String[] args){
      SwingLayoutDemo swingLayoutDemo = new SwingLayoutDemo();  
      swingLayoutDemo.showGridBagLayoutDemo();       
   }
      
   private void prepareGUI(){
      mainFrame = new JFrame("Java SWING Examples");
      mainFrame.setSize(400,400);
      mainFrame.setLayout(new GridLayout(3, 1));

      headerLabel = new JLabel("",JLabel.CENTER );
      statusLabel = new JLabel("",JLabel.CENTER);        

      statusLabel.setSize(350,100);
      mainFrame.addWindowListener(new WindowAdapter() {
         上一篇:Swing教程首頁下一篇:Swing Layout布局