氟塑料離心泵www.buybeng.com

          jquery教程http://www.software8.co/wzjs/jquery/

          GridBagLayout的使用

          是java中最有彈性但也是最復雜的一種版面管理器。它只有一種構造函數,但必須配合GridBagConstraints才能達到設置的效果。
          GridBagLayout的類層次結構圖:
              java.lang.Object
               --java.awt.GridBagLayout
          構造函數:
              GirdBagLayout()建立一個新的GridBagLayout管理器。
              GridBagConstraints()建立一個新的GridBagConstraints對象。
              GridBagConstraints(int gridx,int gridy,int gridwidth,int gridheight,double weightx,double weighty,
                                 int anchor,int fill, Insets insets,int ipadx,int ipady)建立一個新的GridBagConstraints對象
                                ,并指定其參數的值。
          參數說明:
          gridx,gridy:設置組件的位置,gridx設置為GridBagConstraints.RELATIVE代表此組件位于之前所加入組件的右邊。
                       若將gridy設置為GridBagConstraints.RELATIVE代表此組件位于以前所加入組件的下面。建議定義出
                       gridx,gridy的位置,以便以后維護程序。表示放在幾行幾列,gridx=0,gridy=0時放在0行0列。
           
          gridwidth,gridheight:用來設置組件所占的單位長度與高度,默認值皆為1。你可以使用GridBagConstraints.REMAINDER常
                                量,代表此組件為此行或此列的最后一個組件,而且會占據所有剩余的空間。
           
          weightx,weighty:用來設置窗口變大時,各組件跟著變大的比例,當數字越大,表示組件能得到更多的空間,默認值皆為0。
          anchor:         當組件空間大于組件本身時,要將組件置于何處,有CENTER(默認值)、NORTH、NORTHEAST、EAST、SOUTHEAST、
                           WEST、NORTHWEST可供選擇。
          insets:設置組件之間彼此的間距,它有四個參數,分別是上,左,下,右,默認為(0,0,0,0).
          ipadx,ipady:設置組件內的間距,默認值為0。              
             我們以前提過,GridBagLayout里的各種設置都必須通過GridBagConstraints,因此當我們將GridBagConstraints的參數都設置
          好了之后,必須new一個GridBagConstraints的對象出來,以便GridBagLayout使用。
          例子:
          GridBagLayoutDemo.java
           
          import java.awt.*;
          import java.awt.event.*;
          import javax.swing.*;
          public class GridBagLayoutDemo{
             public GridBagLayoutDemo(){
               JButton b;
               GridBagConstraints c;
               int gridx,gridy,gridwidth,gridheight,anchor,fill,ipadx,ipady;
               double weightx,weighty;
               Insets inset;
               
               JFrame f=new JFrame();
               
               GridBagLayout gridbag=new GridBagLayout();
                 Container contentPane=f.getContentPane();
                 contentPane.setLayout(gridbag);
                 
                 b=new JButton("first");
                 gridx=0;
                 gridy=0;
                 gridwidth=1;
                 gridheight=1;
                 weightx=10;
                 weighty=1;
                 anchor=GridBagConstraints.CENTER;
                 fill=GridBagConstraints.HORIZONTAL;
                 inset=new Insets(0,0,0,0);
                 ipadx=0;
                 ipady=0;
                 c=new GridBagConstraints(gridx,gridy,gridwidth,gridheight,weightx,weighty,anchor,
                    fill,inset,ipadx,ipady);
                 gridbag.setConstraints(b,c);
                 contentPane.add(b);
                 
                 
                 b=new JButton("second");
                 gridx=1;
                 gridy=0;
                 gridwidth=2;
                 gridheight=1;
                 weightx=1;
                 weighty=1;
                 anchor=GridBagConstraints.CENTER;
                 fill=GridBagConstraints.HORIZONTAL;
                 inset=new Insets(0,0,0,0);
                 ipadx=50;
                 ipady=0;
                 c=new GridBagConstraints(gridx,gridy,gridwidth,gridheight,weightx,weighty,anchor,
                    fill,inset,ipadx,ipady);
                 gridbag.setConstraints(b,c);
                 contentPane.add(b);
           
                 b=new JButton("third");
                 gridx=0;
                 gridy=1;
                 gridwidth=1;
                 gridheight=1;
                 weightx=1;
                 weighty=1;
                 anchor=GridBagConstraints.CENTER;
                 fill=GridBagConstraints.HORIZONTAL;
                 inset=new Insets(0,0,0,0);
                 ipadx=0;
                 ipady=50;
                 c=new GridBagConstraints(gridx,gridy,gridwidth,gridheight,weightx,weighty,anchor,
                    fill,inset,ipadx,ipady);
                 gridbag.setConstraints(b,c);
                 contentPane.add(b);
                 
                 b=new JButton("fourth");
                 gridx=1;
                 gridy=1;
                 gridwidth=1;
                 gridheight=1;
                 weightx=1;
                 weighty=1;
                 anchor=GridBagConstraints.CENTER;
                 fill=GridBagConstraints.HORIZONTAL;
                 inset=new Insets(0,0,0,0);
                 ipadx=0;
                 ipady=0;
                 c=new GridBagConstraints(gridx,gridy,gridwidth,gridheight,weightx,weighty,anchor,
                    fill,inset,ipadx,ipady);
                 gridbag.setConstraints(b,c);
                 contentPane.add(b);
           
                 b=new JButton("This is the last button");
                 gridx=2;
                 gridy=1;
                 gridwidth=1;
                 gridheight=2;
                 weightx=1;
                 weighty=1;
                 anchor=GridBagConstraints.CENTER;
                 fill=GridBagConstraints.HORIZONTAL;
                 inset=new Insets(0,0,0,0);
                 ipadx=0;
                 ipady=50;
                 c=new GridBagConstraints(gridx,gridy,gridwidth,gridheight,weightx,weighty,anchor,
                    fill,inset,ipadx,ipady);
                 gridbag.setConstraints(b,c);
                 contentPane.add(b);
           
                 f.setTitle("GridBagLayout");
                 f.pack();
                 f.setVisible(true);
                f.addWindowListener(
                     new WindowAdapter(){
                         public void windowClosing(WindowEvent e){
                            System.exit(0); 
                         } 
                     } 
                );      
             }
             public static void main(String[] args){
               new GridBagLayoutDemo();
             }
          }
          原文參考自站長網:http://www.software8.co/wzjs/java/3475.html

          posted on 2013-03-22 12:21 你爸是李剛 閱讀(1564) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2013年3月>
          242526272812
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          導航

          統計

          常用鏈接

          留言簿

          隨筆檔案

          文章檔案

          技術網站

          行業網站

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          站長網 氟塑料離心泵 注塑機 液晶廣告機
          主站蜘蛛池模板: 广昌县| 周至县| 太仓市| 宁化县| 黎川县| 息烽县| 武川县| 铁力市| 资中县| 巨鹿县| 奉新县| 怀化市| 扎囊县| 广汉市| 万源市| 会东县| 台北县| 河间市| 昌黎县| 习水县| 电白县| 梅河口市| 徐水县| 施秉县| 明水县| 怀来县| 浪卡子县| 建宁县| 河东区| 邓州市| 墨玉县| 德州市| 大化| 安陆市| 陕西省| 色达县| 泾川县| 阿拉善右旗| 清水县| 临洮县| 加查县|