<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                ## 網格布局特點: * 使容器中的各組件呈M行×N列的網格狀分布。 * 網格每列寬度相同,等于容器的寬度除以網格的列數。 * 網格每行高度相同,等于容器的高度除以網格的行數。 * **組件放入容器的次序決定了它在容器中的位置。** * 容器大小改變時,組件的相對位置不變,大小會改變。 * 設置網格布局行數和列數時,行數或者列數可以有一個為零。若rows為0,cols為3,則列數固定為3,行數不限,每行只能放3個控件或容器。若cols為0,rows為3,則行數固定為3,列數不限,且每行必定有控件,若組件個數不能整除行數,則除去最后一行外的所有行組件個數為:Math.ceil(組件個數/rows)。 Math.ceil(double x):傳回不小于x的最小整數值。比如行數為3,組件數為13個,則Math.ceil(13/3)=5,即第一行,第二行組件數各為5個,剩下的組件放在最后一行。 * 若組件數超過網格設定的個數,則布局管理器會自動增加網格個數,原則是保持行數不變。 ## 構造方法摘要 GridLayout(): 創建具有默認值的網格布局,即每個組件占據一行一列。 GridLayout(int rows, int cols) :創建具有指定行數和列數的網格布局。Rows為行數,cols為列數。 GridLayout(int rows, int cols, int hgap, int vgap) :創建具有指定行數、列數以及組件水平、縱向一定間距的網格布局。 ## 方法摘要 getColumns() :獲取此布局中的列數。 getHgap():獲取組件之間的水平間距。 getRows() :獲取此布局中的行數。 getVgap() :獲取組件之間的垂直間距。 removeLayoutComponent(Component comp) :從布局移除指定組件。 setColumns(int cols) :將此布局中的列數設置為指定值。 setHgap(int hgap):將組件之間的水平間距設置為指定值。 setRows(int rows):將此布局中的行數設置為指定值。 setVgap(int vgap) :將組件之間的垂直間距設置為指定值。 toString():返回此網格布局的值的字符串表示形式。 ### demo ``` import java.awt.BorderLayout; import java.awt.GridLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.SwingConstants; /* * 2015-06-10 */ public class GridLayoutDemo extends JFrame{ JButton resultButton = new JButton("0"); JPanel panel = new JPanel(); public GridLayoutDemo() { //set to BorderLayout setLayout(new BorderLayout()); add(resultButton, BorderLayout.NORTH); add(panel, BorderLayout.CENTER); //gridLayout GridLayout gridLayout = new GridLayout(4,4,3,3); panel.setLayout(gridLayout); //add buttons String [] buttonNames = new String []{"7", "8","9","/","4","5","6","*","1","2","3","-","0",".","=","+"}; for (String string : buttonNames) { panel.add(new JButton(string)); } //config resultButton resultButton.setSize(200, 50); resultButton.setHorizontalAlignment(SwingConstants.RIGHT); resultButton.setEnabled(false); //setSize(250,200); pack(); setTitle("GridLayoutDemo"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocationRelativeTo(null); } public static void main(String[] args) { // TODO Auto-generated method stub GridLayoutDemo demo = new GridLayoutDemo(); demo.setVisible(true); } } ``` 運行界面如圖1所示: ![](https://box.kancloud.cn/96b537f329e9343f2f71d1fdb0f56216_262x208.png) ![](https://box.kancloud.cn/78d645acab9bafe30dd9adfa5eb79f04_509x401.png)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看