3.4 面板
JPanel
package GUI.Swing;
import javax.swing.*;
import java.awt.*;
public class JPanelDemo extends JFrame {
public JPanelDemo(){
Container container = this.getContentPane();
container.setLayout(new GridLayout(2,1,10,10));//后面参数的意思是间距
Panel panel1 = new Panel(new GridLayout(1,3));
panel1.add(new JButton("1"));
panel1.add(new JButton("1"));
panel1.add(new JButton("1"));
container.add(panel1);
this.setVisible(true);
this.setSize(500,500);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new JPanelDemo();
}
}
JScroll 边框
package GUI.Swing;
import javax.swing.*;
import java.awt.*;
public class JScrollDemo extends JFrame {
public JScrollDemo(){
Container container = this.getContentPane();//容器
//文本域
JTextArea textArea = new JTextArea(20, 30);
textArea.setText("欢迎观看鹿鹿的学习日记!");//设置默认的文字
//Scroll面板
JScrollPane scrollPane = new JScrollPane(textArea);//在面板中放文本域
container.add(scrollPane);//在容器中放面板
this.setVisible(true);
this.setBounds(100,100,300,300);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new JScrollDemo();
}
}