我在试着清除JTextArea。
目前,我正在使用
jtextarea.setText(null);如果我使用
jtextarea.setText("");发布于 2013-04-04 05:38:08
这是没有区别的。它们都具有删除旧文本的效果。在java TextComponent页面中:
setText
public void setText(String t)
Sets the text of this TextComponent to the specified text. If the text is null
or empty, has the effect of simply deleting the old text. When text has been
inserted, the resulting caret location is determined by the implementation of
the caret class.
Note that text is not a bound property, so no PropertyChangeEvent is fired when
it changes. To listen for changes to the text, use DocumentListener.
Parameters:
t - the new text to be set
See Also:
getText(int, int), DefaultCaret发布于 2018-10-23 14:17:17
作者尝试的是清除JTextArea,而不是在其中添加空字符!
JTextArea0.selectAll();
JTextArea0.replaceSelection("");这将选择整个textArea,然后将其替换为空字符串,从而有效地清除JTextArea。
不知道这里的误解是什么,但我也有同样的问题,这个答案为我解决了这个问题。
发布于 2017-05-29 14:32:21
JTextArea0.selectAll();
JTextArea0.replaceSelection("");https://stackoverflow.com/questions/15798532
复制相似问题