[英]threading issues with java swing and web start
EDIT: After fixing a few issues, the bigger issue that I am having is being caused by Apache POI which I am using. 编辑:解决了一些问题后,我遇到的更大问题是由我使用的Apache POI引起的。 I am working on figuring that out now.
我正在努力弄清楚这一点。 Apparently it is being restricted by the Sandbox.
显然,它受到沙箱的限制。
I'm very new to Swing, and created a small Swing app that I now need to have run via web start. 我是Swing的新手,并创建了一个小型Swing应用程序,现在需要通过网络启动来运行它。 I'm trying to use the FileOpenService and update a Text display.
我正在尝试使用FileOpenService并更新文本显示。 I think I am running into threading issues, because the FileOpenService dialog never appears, and my text display is not getting updated.
我认为我遇到了线程问题,因为FileOpenService对话框从未出现,并且我的文本显示没有得到更新。
I can't really find any examples where they are doing anything different than I am right now. 我真的找不到任何例子,说明他们在做与我现在不同的事情。
Ideas? 有想法吗?
Thanks! 谢谢!
Edit: I now have the FileOpenService dialog appearing. 编辑:我现在出现FileOpenService对话框。 I changed my main to this:
我将主要更改为:
public static void main(String[] args) throws Exception {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
new MainFrame();
}
});
}
However, I still can't get my display to update. 但是,我仍然无法更新我的显示。 This is where I am doing the update:
这是我进行更新的地方:
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);
}
and my append method: 和我的append方法:
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();
}
}
You are calling *.openFileDialog(foo,bar) right? 您呼叫* .openFileDialog(FOO,吧)吧?
FileOpenService fos = (FileOpenService)ServiceManager.lookup("javax.jnlp.FileOpenService");
FileContents fc = fos.openFileDialog(null, null);
Sorry if this is a dumb question, but until you update your question with source I can't think of much else. 抱歉,这是一个愚蠢的问题,但是在您使用源代码更新问题之前,我什至没有想到。
The problem I was having had nothing to do with any of this. 我所遇到的问题与此无关。 In another part of my code right near where I was trying to do this, I was causing an application exit.
在我尝试执行此操作的位置附近的代码的另一部分中,我导致了应用程序退出。 It was a hold over from something else I was trying out that got missed when I was working on implementing this.
这是我尝试执行的其他操作的延误,而我在实施此操作时却错过了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.