氟塑料離心泵www.buybeng.com

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

          GridBagLayout的使用

          是java中最有彈性但也是最復雜的一種版面管理器。它只有一種構(gòu)造函數(shù),但必須配合GridBagConstraints才能達到設置的效果。
          GridBagLayout的類層次結(jié)構(gòu)圖:
              java.lang.Object
               --java.awt.GridBagLayout
          構(gòu)造函數(shù):
              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對象
                                ,并指定其參數(shù)的值。
          參數(shù)說明:
          gridx,gridy:設置組件的位置,gridx設置為GridBagConstraints.RELATIVE代表此組件位于之前所加入組件的右邊。
                       若將gridy設置為GridBagConstraints.RELATIVE代表此組件位于以前所加入組件的下面。建議定義出
                       gridx,gridy的位置,以便以后維護程序。表示放在幾行幾列,gridx=0,gridy=0時放在0行0列。
           
          gridwidth,gridheight:用來設置組件所占的單位長度與高度,默認值皆為1。你可以使用GridBagConstraints.REMAINDER常
                                量,代表此組件為此行或此列的最后一個組件,而且會占據(jù)所有剩余的空間。
           
          weightx,weighty:用來設置窗口變大時,各組件跟著變大的比例,當數(shù)字越大,表示組件能得到更多的空間,默認值皆為0。
          anchor:         當組件空間大于組件本身時,要將組件置于何處,有CENTER(默認值)、NORTH、NORTHEAST、EAST、SOUTHEAST、
                           WEST、NORTHWEST可供選擇。
          insets:設置組件之間彼此的間距,它有四個參數(shù),分別是上,左,下,右,默認為(0,0,0,0).
          ipadx,ipady:設置組件內(nèi)的間距,默認值為0。              
             我們以前提過,GridBagLayout里的各種設置都必須通過GridBagConstraints,因此當我們將GridBagConstraints的參數(shù)都設置
          好了之后,必須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();
             }
          }
          原文參考自站長網(wǎng):http://www.software8.co/wzjs/java/3475.html

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


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


          網(wǎng)站導航:
           
          <2013年3月>
          242526272812
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          導航

          統(tǒng)計

          常用鏈接

          留言簿

          隨筆檔案

          文章檔案

          技術網(wǎng)站

          行業(yè)網(wǎng)站

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          站長網(wǎng) 氟塑料離心泵 注塑機 液晶廣告機
          主站蜘蛛池模板: 瓦房店市| 盘山县| 永川市| 邵东县| 常山县| 迭部县| 都昌县| 扶风县| 黔南| 宁津县| 当阳市| 铜川市| 温泉县| 延边| 寿阳县| 临漳县| 台南县| 博湖县| 揭西县| 漯河市| 永吉县| 丰原市| 翁源县| 崇明县| 延川县| 上栗县| 高清| 郯城县| 山阳县| 阿鲁科尔沁旗| 饶河县| 隆回县| 宣威市| 宁城县| 将乐县| 丰顺县| 贵港市| 亚东县| 杂多县| 宁蒗| 巴里|