其他分享
首页 > 其他分享> > JScorll文本域

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();
    }
}

 

标签:container,panel4,Button,JPanel,add,new,文本,JScorll
来源: https://www.cnblogs.com/zhangtiedangg/p/15654224.html