一、创建一个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);
JTextArea textArea = new JTextArea(20, 20);
textArea.setText("hello textArea");
JScrollPane jScrollPane = new JScrollPane(textArea);
Container contentPane = this.getContentPane();
contentPane.add(jScrollPane);
}
public static void main(String[] args) {
new JscrollPaneDemo();
}
}
未知错误:无法显示
解决,进行窗口拖拽即可,