java jtextarea清空_Java JTextArea.setCaret方法代码示例

import javax.swing.JTextArea; //导入方法依赖的package包/类

@Override

protected void initGUI() {

// textView = new JEditorPane();

// textView.setContentType("text/plain");

// textView.setEditorKit(new RawEditorKit());

textView = new JTextArea();

textView.setAutoscrolls(false);

textView.setLineWrap(true);

textView.setWrapStyleWord(true);

// the selection is hidden when the focus is lost for some system

// like Linux, so we make sure it stays

// it is needed when doing a selection in the search textfield

textView.setCaret(new PermanentSelectionCaret());

scroller = new JScrollPane(textView);

textView.setText(document.getContent().toString());

textView.getDocument().addDocumentListener(swingDocListener);

// display and put the caret at the beginning of the file

SwingUtilities.invokeLater(new Runnable() {

@Override

public void run() {

try {

if(textView.modelToView(0) != null) {

textView.scrollRectToVisible(textView.modelToView(0));

}

textView.select(0, 0);

textView.requestFocus();

} catch(BadLocationException e) {

e.printStackTrace();

}

}

});

// contentPane = new JPanel(new BorderLayout());

// contentPane.add(scroller, BorderLayout.CENTER);

// //get a pointer to the annotation list view used to display

// //the highlighted annotations

// Iterator horizViewsIter = owner.getHorizontalViews().iterator();

// while(annotationListView == null && horizViewsIter.hasNext()){

// DocumentView aView = (DocumentView)horizViewsIter.next();

// if(aView instanceof AnnotationListView)

// annotationListView = (AnnotationListView)aView;

// }

highlightsMinder = new Timer(BLINK_DELAY, new UpdateHighlightsAction());

highlightsMinder.setInitialDelay(HIGHLIGHT_DELAY);

highlightsMinder.setDelay(BLINK_DELAY);

highlightsMinder.setRepeats(true);

highlightsMinder.setCoalesce(true);

highlightsMinder.start();

// blinker = new Timer(this.getClass().getCanonicalName() +

// "_blink_timer",

// true);

// final BlinkAction blinkAction = new BlinkAction();

// blinker.scheduleAtFixedRate(new TimerTask(){

// public void run() {

// blinkAction.actionPerformed(null);

// }

// }, 0, BLINK_DELAY);

initListeners();

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值