public class JPanelDemo01 extends JFrame {
public JPanelDemo01(){
Container container = this.getContentPane();
container.setLayout(new GridLayout(2,1,10,10));//表格容器后面两个数字代表间距
JPanel jPanel1 = new JPanel(new GridLayout(1,3));
JPanel jPanel2 = new JPanel(new GridLayout(1,2));
JPanel jPanel3 = new JPanel(new GridLayout(2,1));
JPanel jPanel4 = new JPanel(new GridLayout(3,2));
jPanel1.add(new Button("1"));
jPanel1.add(new Button("1"));
jPanel1.add(new Button("1"));
jPanel1.add(new Button("2"));
jPanel1.add(new Button("2"));
jPanel1.add(new Button("3"));
jPanel1.add(new Button("3"));
jPanel1.add(new Button("4"));
jPanel1.add(new Button("4"));
jPanel1.add(new Button("4"));
jPanel1.add(new Button("4"));
jPanel1.add(new Button("4"));
jPanel1.add(new Button("4"));
container.add(jPanel1);
container.add(jPanel2);
container.add(jPanel3);
container.add(jPanel4);
this.setVisible(true);
this.setBounds(200,200,400,400);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new JPanelDemo01();
}
}
JScoll
import javax.swing.*;
import java.awt.*;
public class JScollDemo extends JFrame {
public JScollDemo(){
Container container = this.getContentPane();
//文本域
JTextArea textArea = new JTextArea(20,50);
textArea.setText("开心的学习java");
//Scoll面板
JScrollPane jScrollPane1 = new JScrollPane(textArea);
container.add(jScrollPane1);
this.setVisible(true);
this.setBounds(200,200,400,400);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new JScollDemo();
}
}