自动调整大小和滚动的Java JTextArea [英] Java JTextArea that auto-resizes and scrolls

查看:690
本文介绍了自动调整大小和滚动的Java JTextArea的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JPanel中有一个JTextArea.我如何才能让JTextArea填充整个JPanel并重新调整大小,而当JPanel调整大小并在键入太多文本时滚动呢?

I have a JTextArea in a JPanel. How can I have the JTextArea fill the whole JPanel and resize when the JPanel resizes and scroll when too much text is typed in?

推荐答案

JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());  //give your JPanel a BorderLayout

JTextArea text = new JTextArea(); 
JScrollPane scroll = new JScrollPane(text); //place the JTextArea in a scroll pane
panel.add(scroll, BorderLayout.CENTER); //add the JScrollPane to the panel
// CENTER will use up all available space

请参见 http://download.oracle.com /javase/6/docs/api/javax/swing/JScrollPane.html http://download.oracle.com/javase/tutorial/uiswing/components/scrollpane.html 了解有关JScrollPane的更多详细信息

See http://download.oracle.com/javase/6/docs/api/javax/swing/JScrollPane.html or http://download.oracle.com/javase/tutorial/uiswing/components/scrollpane.html for more details on JScrollPane

这篇关于自动调整大小和滚动的Java JTextArea的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆