-1

我正在研究具有多个组件的 Java 程序。我想要实现的是,任何异常都显示在 JTextArea 中,而不是控制台中。下面的代码不起作用。我能做些什么?

catch ( MalformedURLException e) { textArea.append(e); }

谢谢

4

1 回答 1

0

JTextArea 不支持 append() 方法。如果你只需要显示错误,你可以试试这个:

catch ( MalformedURLException e) { textArea.setText(e.toString()); }

如果您需要附加消息,您可以试试这个:

catch ( MalformedURLException e) { textArea.setText(textArea.getText()+e.toString()); }
于 2013-03-04T16:10:09.913 回答