java JscrollPane 滚动条面板使用教程

一、创建一个Frame

二、new TextArea 然后将 textArea 放到滚动面板JscrollPane中。

new JscrollPane(textArea);

三、将滚动面板放到 容器里

总代码:

package GUI.Swing.滚动面板JscrollPane;

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

public class JscrollPaneDemo extends JFrame {
    public JscrollPaneDemo() throws HeadlessException {
        this.setVisible(true);
        this.setBounds(100, 100, 400, 400);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        //new a TextArea
        JTextArea textArea = new JTextArea(20, 20);
        textArea.setText("hello textArea");
        //new JScrollPane and add textArea to jScrollPane
        JScrollPane jScrollPane = new JScrollPane(textArea);
        //add js to container
        Container contentPane = this.getContentPane();
        contentPane.add(jScrollPane);
    }

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


未知错误:无法显示

解决,进行窗口拖拽即可,

在这里插入图片描述

发布了56 篇原创文章 · 获赞 2 · 访问量 466

猜你喜欢

转载自blog.csdn.net/jarvan5/article/details/105645645