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

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.

Related

Any workaround for Java/Swing bug under Mac OS when opening new windows as tabs

I'm developing a swing based Java application (Java 8) for Mac and Windows. Some users have set the mac system preference under "General" "Prefer Tabs when opening documents" to "Always" or "Full screen". When the setting is set to "Never" it works without problems.
This setting causes some weird state in which the window opens a new tab which results in a frozen application which can only be force quitted. I cannot assume that users know about this hidden setting in the Mac OS system preferences.
Three solutions would work for me:
Find any workaround to prevent the window from opening other windows as tabs?
Launching our bundled Java app with some -flag that disables this behaviour for the entire application
Detecting if this mac system setting is enabled and then warn the user and quit the application (not really a good solution)
This change in Big Sur is causing a bug in Java https://bugs.openjdk.java.net/browse/JDK-8256465
There is a workaround from MacOS terminal window you can run
defaults write net.java.openjdk.cmd "AppleWindowTabbingMode" manual
or if you have java bundled within your own application use the value of CFBundleIdentifier in the applications Info.plist file
e.g
defaults write net.myapp.com "AppleWindowTabbingMode" manual

java application on Windows 8 start screen

I have been googling on this but I can't find the answer.
Can anyone tell me if you can put a Java application on the windows 8 start screen?
According to java.com
When will Java be supported in Windows 8? Windows 8 is officially
supported with the release of Java 7 Update 10. Java will only be
supported in Desktop screen. Java will not run in the Start screen.
I am not sure how to interpret this since I do not know the startscreen of Windows 8 and they talk about internet explorer 10 on the same page which makes me think they may only be talking about the browser.
Basically I want to have a tile to act like a classic windows icon. Is this the way it works and is this the way you can run a java application? Or do you need to go to the desktop interface first?
No. You can't.
All the apps on the Windows 8 start screen are the apps downloaded from the Windows Store.
All the other Java applications that you develop will run in the desktop environment, but not in the start screen.
As per this source, you can look forward towards creating apps for Windows Store using Java and then you can maybe think of putting a Java application on the Windows start screen.
You cannot put directly a Java application in the start screen in windows 8 (just as you couldn't create shortcut icons on the Desktop in Windows 7), however notice this is rarely what you want with a Windows desktop application.
Most of the times you will want to wrap your Java desktop application with a windows installer which will put the start screen icon on windows 8.
Your Java code will then be launched by the installer executable which might do some house cleaning jobs like checking what compatible version of Java is installed in the computer and if required install a newer one.

Changing wallpaper and stretch it on Windows platform using Java(with JNA)

I am looking for a way to change the wallpaper on Windows 7 using the "Stretched" method in Java.
I found this:
Can I change my Windows desktop wallpaper programmatically in Java/Groovy?
This approach work but uses the "Centered" method.
I also tried to import the Jawc project into eclipse, but I get runtime errors I can't resolve(Stacktrace: http://pastebin.com/Dqmsgqtv).

Pinning a Java executable (with launch4j) to the Windows 7 taskbar

After spending half a day searching and trying, I'm finally giving up.
I have a java application of which I create a runnable jar (to include any other libs and just have a single jar file). With launch4j and the runnable jar I'm making an executable "MyApp.exe".
The executable ist working fine, but I want to pin it to my windows 7 taskbar. For now, I just have the taskbar entry "Close window".
After reading and implementing the following solutions with JNA
Pinning a Java application to the Windows 7 taskbar
Using JNA to get/set application identifier
my Application displays it's "Application User Model ID" correctly in the gui (just for testing purpose).
BUT: my program is shown as "javaw.exe" in the Task Manager and I still can't pin it to the taskbar, even though I set the launch4j option "custom process name and XP style manifest".
Background information: I'm working with a windows 7 admin account and I don't want the app the require admin rights.
Anyways, if I start the app "as administrator" from the context menu and confirm the UAC message, I can now pin to the taskbar. BUT: even though I set the "Application User Model ID" properly, windows still wants to pin "javaw.exe", even though my program is now shown as "MyApp.exe" in the TaskManager.
I'm totaly confused. But I'm obviously not the only one, having these issues.
=> See the last comments to Gregory Pakosz answer in Using JNA to get/set application identifier
Final questions:
Gregory Pakosz way with JNA to set the "Application User Model ID" ( https://stackoverflow.com/a/1928830/1128689 ) is working for me. But still, windows recognizes my app as an instance of "javaw.exe". What else do I have to do?
Did maybe some windows or java update break something here?
Do I really have to run my app with elevated user rights? I really don't want to...
Are there some more options in launch4j which I have to set?
Do I have to use a manifest file in launch4j?
I got this working by creating an Exe from a runnable jar with the help of JSmooth
.Pinned it to the taskbar, and ran it with no problems.
Hope this helps
No problem with winrun4j either, which is newer and easier to use than Jsmooth
The root cause: javaw is registered as a Host process (in Windows' registry). The shortcut behaviour is probably caused by following (source: Application User Model IDs (AppUserModelIDs))
Application-Defined and System-Defined AppUserModelIDs
Some applications do not declare an explicit AppUserModelID. They are
optional. In that case, the system uses a series of heuristics to
assign an internal AppUserModelID.
[...]
if the process was launched through a shortcut that contains launch
arguments (usually the target content to host as the "application"),
the system can determine identity and the application can be pinned
and relaunched.
About the Host Process behaviour:
Registering an Application as a Host Process
An application can set
the IsHostApp registry entry to cause that executable's process to be
considered a host process by the taskbar. This affects its grouping
and default Jump List entries.
Are you looking for this, which I used in my application to show the running Java application on windows taskbar..
SystemTray systemTray = new SystemTray(composite, parent.getShell(), parent.getDisplay(), "My Application");
systemTray.makeSystemTray();

Java UI on macOS X Lion

I'm having a strange bug wich i suspect to be specific to either MacOS X Lion and/or Java VM implementation on this OS.
When a java app summons a secondary window like a dialog box, i'm often unable to interact with its content ie. click, use menus, etc.
At first i though my app was buggy but since i had developped it on windows (where it worked fine) and switched to mac. I though some weird swing setting was to blame and i had noticed on the console that a compatibility mode with cocoa was enabled when i launched my app.
But i encountered the same bug with eclipse itself (a well known java based ide) tough it does not always happen in it while it's all the time with my app.
I have browsed for this issue but found nothing. Meanwhile i found that there is an issue between oracle and apple about java. I downladed a java update specific to Lion but the bug is still here
My question is : have you encountered the same bug ? is it macos lion specific ? have you found a workaround ??
Thanks
Made some research. Eclipse seems to be the cause of the bug. More precisely SWT support in eclipse under MacOS environnement.
The bug is not present with netbeans.

Categories

Resources