JTextarea的设置

来源:互联网 发布:阿波罗20号 知乎 编辑:程序博客网 时间:2024/05/16 17:26

JTextArea 设置滚动条(也是随着添加文字而滚动):

方法一:

JTextArea infos=new JTextArea ();

JScrollBar bar=new JScrollBar();

JScrollPanescrollPane;

//设置滚动条
scrollPane = new JScrollPane(infos);
  //设置只显示竖直的滚动条
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

bar=scrollPane.getHorizontalScrollBar();

bar.setValue(infos.getDocument().getLength());

 

方法二:

infos.setCaretPosition(infos.getDocument().getLength());

 

 

//设置JTextArea自动换行
infos.setLineWrap(true);

0 0