【问题标题】:Displaying MalformedURLException in JTextArea在 JTextArea 中显示 MalformedURLException
【发布时间】:2013-03-04 16:07:15
【问题描述】:
我正在开发具有多个组件的 Java 程序。我想要实现的是,任何异常都显示在 JTextArea 中,而不是控制台中。下面的代码不起作用。我能做些什么?
catch ( MalformedURLException e) {
textArea.append(e); }
谢谢
【问题讨论】:
标签:
java
jtextarea
malformedurlexception
【解决方案1】:
JTextArea 不支持 append() 方法。
如果你只需要显示错误,你可以试试这个:
catch ( MalformedURLException e) { textArea.setText(e.toString()); }
如果你需要附加消息,你可以试试这个:
catch ( MalformedURLException e) { textArea.setText(textArea.getText()+e.toString()); }