表格布局是按照表格的样式来放置按钮,如下:
package com.fepc.commons.exports;
import java.awt.Dimension;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
public class SwingTest extends JDialog{
public SwingTest(){
this.setLayout(new GridLayout(3,3)); /*设置布局,三行三列*/
this.setPreferredSize(new Dimension(380, 300));//设置大小
this.setTitle("表格布局");
this.setVisible(true);//设置dialog显示
this.pack();
JButton but1=new JButton("button1");
JButton but2=new JButton("button2");
JButton but3=new JButton("button3");
JButton but4=new JButton("button4");
JButton but5=new JButton("button5");
JButton but6=new JButton("button6");
JButton but7=new JButton("button7");
add(but1);
add(but2);
add(but3);
add(but4);
add(but5);
add(but6);
add(but7);
}
public static void main(String[] args) {
new SwingTest();
}
}
显示如下: