开发者

threading issues with java swing and web start

开发者 https://www.devze.com 2022-12-13 22:10 出处:网络
EDIT: After fixing a few issues, the bigger issue that I am having is being caused by Apache POI which I am using. I am working on figuring that out now. Apparently it is being restricted by the Sandb

EDIT: After fixing a few issues, the bigger issue that I am having is being caused by Apache POI which I am using. 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. I'm trying to use the FileOpenService and update a Text display. I think I am running into threading issues, because the FileOpenService dialog never a开发者_C百科ppears, and my text display is not getting updated.

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. 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:

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?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消