zimmerrol
zimmerrol

Reputation: 4951

Java/Swing: Desktop.open() causes GTK-ERROR

I am currently developing a Swing Desktop application. This application is also using a tray icon which is handled by SystemTray of dorkbox.

Now I need to open a file with the default application. To achieve this I am using the Desktop.open() method of AWT like this.

if (Desktop.isDesktopSupported()) {
    System.out.println("Get desktop.");
    Desktop desktop = Desktop.getDesktop();
    System.out.println("Got desktop.");
    desktop.open(file);
}

But now here comes the problem: On some devices (which apparently have GTK2 and GTK3 installed this few lines make application crash - the program crashes while executing the Desktop.isDesktopSupported() line with a gtk-error ** gtk+ 2.x symbols detected. using gtk+ 2.x and gtk+ 3 is not supported.

To be honest, I have no clue, what is going wrong here - but if only GTK3 is installed the application runs like a charm. The SystemTray seems to be using GTK3 as well because I did not explicitly set it up to use GTK2. So, what's causing this mix of GTK2 and 3? Is there a way to force the Desktop class to use the right version of GTK (the same, as being used by the rest of the application)?

Upvotes: 4

Views: 438

Answers (1)

D. Krauchanka
D. Krauchanka

Reputation: 274

It won't resolve your current problem but there is another way to open file with the default application.

On Windows:

Runtime.getRuntime().exec("C:\SomeFolder\Somefile.txt");

On Mac and Linux:

Runtime.getRuntime().exec("xdg-open /folder/file.txt");

Hope it will help you, if you won't resolve your current problem.

Upvotes: 2

Related Questions