Java / Swing:Desktop.open()导致GTK-ERROR [英] Java/Swing: Desktop.open() causes GTK-ERROR
问题描述
我目前正在开发一个 Swing
桌面应用程序。此应用程序还使用由 SystemTray
处理的托盘图标。的dorkbox 。
现在我需要用默认应用程序打开一个文件。为了达到这个目的,我使用了
这样的 Desktop.open()
方法。
if(Desktop.isDesktopSupported()){
System.out.println(Get desktop。);
桌面桌面= Desktop.getDesktop();
System.out.println(Got desktop。);
desktop.open(file);
}
但现在问题出现了:在某些设备上(显然有GTK2和GTK3安装了这几行代码会导致应用程序崩溃 - 程序在执行 Desktop.isDesktopSupported()
行时崩溃,并且出现 gtk-error ** gtk + 2。使用gtk + 2.x和gtk + 3不支持
。
老实说,我不知道,发生了什么事这里错了 - 但是如果只安装了GTK3,应用程序会像魅力一样运行。 SystemTray
似乎也在使用GTK3,因为我没有明确地设置它来使用GTK2。
那么,是什么导致了GTK2和3的混合?有没有办法强制 Desktop
类使用右版本的GTK(与应用程序的其余部分一样)?
它不会解决您目前的问题,但还有另一种方法可以使用默认应用程序打开文件。
在Windows上:
Runtime.getRuntime().exec(C:\SomeFolder\Somefile.txt);
在Mac和Linux上:
Runtime.getRuntime()。exec(xdg-open /folder/file.txt);
如果您不能解决目前的问题,希望它能帮助您。
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)?
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.
这篇关于Java / Swing:Desktop.open()导致GTK-ERROR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!