0
点赞
收藏
分享

微信扫一扫

【JAVAGUI】Swing—面板

玉新行者 2022-05-04 阅读 147
java

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

在这里插入图片描述

举报

相关推荐

0 条评论