JScorll文本域

JScorll文本域

JScorllUse类

package com.zhang.Study.文本域;

import javax.swing.*;
import java.awt.*;

public class JScrollUse extends JFrame {
    public  JScrollUse(){
        Container container = this.getContentPane();
        container.setLayout(new GridLayout(2,1,10,10));//設置容器内布局,hgap和vgap设置表格的上下间距
        JPanel panel1 = new JPanel(new GridLayout(1,3));
        JPanel panel2 = new JPanel(new GridLayout(1,2));
        JPanel panel3 = new JPanel(new GridLayout(2,1));
        JPanel panel4 = new JPanel(new GridLayout(2,2));
        panel1.add(new Button("1"));
        panel1.add(new Button("1"));
        panel1.add(new Button("1"));
        panel2.add(new Button("2"));
        panel2.add(new Button("2"));
        panel3.add(new Button("3"));
        panel3.add(new Button("3"));
        panel4.add(new Button("4"));
        panel4.add(new Button("4"));
        panel4.add(new Button("4"));
        panel4.add(new Button("4"));
        container.add(panel1);
        container.add(panel2);
        container.add(panel3);
        container.add(panel4);
        setVisible(true);
        setSize(500,500);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }

    public static void main(String[] args) {
        new  JScrollUse();
    }

}

JtextUse

package com.zhang.Study.文本域;

import javax.swing.*;
import java.awt.*;

public class JTextAreaUse  extends JFrame {
    public JTextAreaUse(){
        Container container = this.getContentPane();
        //文本域
        JTextArea textArea = new JTextArea(20,50);
        textArea.setText("欢迎");
        //Scorll面板
        JScrollPane scrollPane = new JScrollPane(textArea);
        container.add(scrollPane);
        setVisible(true);
        setBounds(400,400,400,400);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }

    public static void main(String[] args) {
        new JTextAreaUse();
    }
}

 

posted on 2021-12-07 08:48  张铁蛋666  阅读(53)  评论(0编辑  收藏  举报

导航