views:

47

answers:

1

Hi, I have a problem with a java gui and opening a document. My problem is the complete gui hangs until the document is open, but I already threaded the action...

I have this action listener:

    this.EditButton.addActionListener(new ActionListener(){
        @Override
        public void actionPerformed(ActionEvent arg0) {
            String path = (String)DocumentsTable.getValueAt(DocumentsTable.getSelectedRow(), 2);
            openDocument(path);
            System.out.println("foo");
        }
    });

the action which is performed just opens the given path

private void openDocument(final String path){
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            try{
                Desktop.getDesktop().open(new File(path));
            }
            catch(Exception e){
                JOptionPane.showMessageDialog(null, "Das Dokument konnte nicht geöffnet werden...\n"+e.toString());
                e.printStackTrace();
            }
        }
    });
}

If I run my program I immediately see "foo" on console but the gui completly hangs up and the button is in pressed state... Does anyone have an idea what I did wrong? My other action listeners work the same and I don't have the problem there...

+2  A: 

SwingUtilities.invokeLater() schedules the runnable to be run on the EDT, as is stated in the javadoc. Perhaps you should be using a SwingWorker to open the doc?

Qwerky
For simplicity, EDT == Event dispatching thread == gui thread
Ishtar
thanks, it worked :) mh i should change all invokeLater to SwingWorkers...
reox