[英]How to make JTextArea scrollable to user input?
幾天以來我一直在研究Java應用程序(我是新手)。 我必須使用JTextArea
進行用戶輸入(250個字符)。 我已經使用setPreferredSize()
方法來調整JTextArea
大小。 但是,隨着用戶的鍵入,當插入的單詞超過JTextArea
高度時,盡管用戶鍵入,但我看不到其余的輸入。
有辦法解決這個問題嗎?
請發布一些代碼,以便我們可以看到您已經做了什么。 您可以嘗試添加JScrollPane
:
JFrame frame = new JFrame ("Frame");
JTextArea textArea = new JTextArea ("Textarea");
JScrollPane scroll = new JScrollPane (textArea,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
frame.add(scroll);//add Scrollbar to frame
請點擊此鏈接
import javax.swing.*;
public class ScrollingTextArea
{
JFrame f;
JTextArea ta;
JScrollPane scrolltxt;
public ScrollingTextArea()
{
// TODO Auto-generated constructor stub
f=new JFrame();
f.setLayout(null);
f.setVisible(true);
f.setSize(500,500);
ta=new JTextArea();
ta.setBounds(5,5,100,200);
scrolltxt=new JScrollPane(ta);
scrolltxt.setBounds(3,3,400,400);
f.add(scrolltxt);
}
public static void main(String[] args)
{
new ScrollingTextArea();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.