编辑:修复了一些问题后,我遇到的更大问题是由我正在使用的 Apache POI 引起的。我现在正在努力解决这个问题。显然它受到沙盒的限制。
我对 Swing 非常陌生,并创建了一个小型 Swing 应用程序,我现在需要通过 web start 运行它。我正在尝试使用 FileOpenService 并更新文本显示。我想我遇到了线程问题,因为 FileOpenService 对话框从未出现,而且我的文本显示没有得到更新。
我真的找不到任何例子,他们正在做与我现在不同的事情。
想法?
谢谢!
编辑:我现在出现了 FileOpenService 对话框。我将主要内容更改为:
public static void main(String[] args) throws Exception {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
new MainFrame();
}
});
}
但是,我仍然无法让我的显示器更新。这是我进行更新的地方:
Runnable r = new Runnable() {
public void run() {
for (final String s : Logger.getMessages())
append(s + "\n");
}
};
try {
if (SwingUtilities.isEventDispatchThread())
r.run();
else
SwingUtilities.invokeAndWait(r);
}
和我的附加方法:
private void append(Color c, String s) {// throws Exception {
StyleContext sc = StyleContext.getDefaultStyleContext();
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY,
StyleConstants.Foreground, c);
int len = _textPaneLog.getDocument().getLength();
try {
_textPaneLog.getDocument().insertString(len, s, aset);
} catch (BadLocationException e) {
e.printStackTrace();
}
}