Javafx Freeze on Desktop.Open(File), Desktop.Browse(Uri)

JavaFX Freeze on Desktop.open(file), Desktop.browse(uri)

I also had the same problem and this solution works for me:

if( Desktop.isDesktopSupported() )
{
new Thread(() -> {
try {
Desktop.getDesktop().browse( new URI( "http://..." ) );
} catch (IOException | URISyntaxException e1) {
e1.printStackTrace();
}
}).start();
}

JavaFX thread issue

I had a similar problem like this. I think the problem lies in the fileOpening stage. The Desktop class you are using comes from java.awt package.When you use the Desktop class then the JAVAFX thread gets blocked as commented by a user in the link given at the bottom of this answer. But the user has a low reputation (only 11)so we cannot rely on him.

To make your application unfreeze, you will have to create a new Thread.
Here is a part of my code, i used in my application and this code worked perfectly. I have also put a link to a github issue of my application where i stated the freezing problem, similar to yours. The issue was created 2 days ago.

@FXML
void openWithAction(ActionEvent event) {
boolean flag = false;
Task task = new Task<Void>() {
@Override
protected Void call() throws Exception {
try {
Desktop.getDesktop().open(new File(fileModel.getFileLocation()));
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
};
new Thread(task).start();
}

Github issue link:
https://github.com/karanpant/SearchEverything/issues/3

I also suggest you to use concurrency provided by JavaFX.
Here is the other SO post link. Hope this helps.
JavaFX Freeze on Desktop.open(file), Desktop.browse(uri)

EDIT: I am sorry if i don't understand your question . Is your question about application freezing or about not being able to pass a parameter or about not being able to pass a parameter because of application freezing.

Desktop.isDesktopSupported() crashes in jar

Although this is not an answer to the question why the Desktop API breaks down when used inside a jar file, I want to point out an alternative that I have found (thanks to @Holger) for my case (working with the eclipse APIs):

You can simply use PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(<YourURL>); in order to open the given URL in the system's default browser.



Related Topics



Leave a reply



Submit