视频链接:17、文本域JScroll面板_哔哩哔哩_bilibili
https://www.bilibili.com/video/BV1DJ411B75F?p=17&vd_source=b5775c3a4ea16a5306db9c7c1c1486b5
1.JPanel
package com.yundait.lesson05;
import javax.swing.*;
import java.awt.*;
public class JPanelDemo extends JFrame {
    public JPanelDemo(){
        //创建容器
        Container container = this.getContentPane();
        //设置容器上组件摆放布局为:2行1列,水平间距10、垂直间距10
        container.setLayout(new GridLayout(2,1,10,10));//后面两个参数的意思是水平间隙、垂直间隙
        //创建4个面板,并设置面板上组件摆放的布局
        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 JButton("1"));
        jPanel1.add(new JButton("2"));
        jPanel1.add(new JButton("3"));
        jPanel2.add(new JButton("4"));
        jPanel2.add(new JButton("5"));
        jPanel3.add(new JButton("6"));
        jPanel3.add(new JButton("7"));
        jPanel4.add(new JButton("8"));
        jPanel4.add(new JButton("9"));
        jPanel4.add(new JButton("10"));
        jPanel4.add(new JButton("11"));
        jPanel4.add(new JButton("12"));
        jPanel4.add(new JButton("13"));
        //在容器上添加面板
        container.add(jPanel1);
        container.add(jPanel2);
        container.add(jPanel3);
        container.add(jPanel4);
        //设置窗口可见、长宽、以及关闭事件
        this.setVisible(true);
        this.setSize(500,500);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }
    public static void main(String[] args) {
        new JPanelDemo();
    }
}
 
运行结果:

2.文本域 JScroll(卷轴)面板
package com.yundait.lesson05;
import javax.swing.*;
import java.awt.*;
public class JScrollDemo extends JFrame {
    public JScrollDemo(){
        //创建一个容器,
        Container container = this.getContentPane();
        //创建文本域
        JTextArea jTextArea = new JTextArea(200,500);
        jTextArea.setText("欢迎来到山东云大网络科技有限公司");
        //创建滚动窗格,并将文本域添加上
        JScrollPane jScrollPane = new JScrollPane(jTextArea);
        //在容器中添加滚动窗格
        container.add(jScrollPane);
        //设置窗口可见、尺寸、关闭事件
        this.setVisible(true);
        this.setBounds(100,100,450,500);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }
    public static void main(String[] args) {
        new JScrollDemo();
    }
}
 
运行结果



















