📄 showgridlayout.java
字号:
/*
* ShowGridLayout.java
*
* Created on 2007年10月20日, 下午10:55
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
import java.awt.Container;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
/**
*
* @author admin
*/
public class ShowGridLayout extends JFrame{
/** Creates a new instance of ShowGridLayout */
public ShowGridLayout() {
//获取窗口的内容面板
Container container = this.getContentPane();
//设置Gridlayout: 4行/3列/水平间距5/垂直间距5
container.setLayout(new GridLayout(4, 3, 5, 5));
//添加按钮到Frame
for (int i = 1; i <= 10; i++) {
container.add(new JButton("Component "+i));
}
}
public static void main(String[] args) {
ShowGridLayout frame = new ShowGridLayout();
frame.setTitle("网格布局");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200, 200);
frame.setVisible(true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -