读书人

JTextPane跟JTextArea禁用(setEdit

发布时间: 2012-12-20 09:53:21 作者: rapoo

JTextPane和JTextArea,禁用(setEditable(false))后,显示光标,并且鼠标为文本光标

JTextPane和JTextArea,禁止编辑(setEditable(false))后,显示光标,并且鼠标为文本光标

?

JTextArea logTxtArea = new JTextArea();//禁止编辑logTxtArea.setEditable(false);//设置鼠标为文本鼠标logTxtArea.setCursor(new Cursor(Cursor.TEXT_CURSOR));//禁止编辑后显示光标logTxtArea.addFocusListener(new FocusListener() {public void focusLost(FocusEvent e) {JTextArea p = (JTextArea)e.getComponent(); p.getCaret().setVisible(false); }public void focusGained(FocusEvent e) {JTextArea p = (JTextArea)e.getComponent(); p.getCaret().setVisible(true); }});

?注意:上边的代码是以JTextArea来做实例的,如果用作JTextPane的话,仅需将JTextArea换为JTextPane即可。

读书人网 >编程

热点推荐