Java的Jtextarea界面 覆盖jFrame 界面
时间: 2024-05-10 18:16:38 浏览: 15
您可以使用JScrollPane将JTextArea添加到JFrame中。JScrollPane可以自动添加滚动条,以便用户可以滚动文本。
以下是一个简单的示例代码:
```
import javax.swing.*;
import java.awt.*;
public class TextAreaExample extends JFrame{
public TextAreaExample(){
setTitle("TextArea Example");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(400,400);
setLocationRelativeTo(null);
JTextArea textArea = new JTextArea();
JScrollPane scrollPane = new JScrollPane(textArea);
getContentPane().add(scrollPane);
}
public static void main(String[] args) {
TextAreaExample example = new TextAreaExample();
example.setVisible(true);
}
}
```
在这个示例中,我们创建了一个JTextArea对象,并把它添加到了一个JScrollPane对象中。然后,我们将JScrollPane添加到JFrame中。这样,JTextArea就会覆盖整个JFrame界面,而且用户可以滚动文本。
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)