Reputation: 35
So the code i'm running is as follows:
import java.awt.*;
import java.io.File;
import java.io.IOException;
public class Main
{
public static void main(String[] args)
{
new Thread(()->{
try
{
Desktop.getDesktop().open(new File(Main.class.getResource("/blank.jpg").getPath()));
} catch (IOException e)
{
System.out.println("oopse");
}
}).start();
}
}
every time it calls Desktop.getDesktop().open(new File(filePath)); and filepath ends in .jpg, for some reason the file is opened in firefox instead of Gwenview.
I want this application to be cross platform, and opening files is a huge part of my application. I need it to respect user preferences for default opening programs. How do i code this so it's friendly to Windows, OsX, and Ubuntu both gnome and plasma?
Here is a fully runnable example: https://github.com/CodingSorcerer/Desktop-Open-Test
Upvotes: 0
Views: 358
Reputation: 35
So I come back to this question much later and it turns out I found the solution. Java doesn't follow the same system preferences as the KDE desktop. To configure the default applications for the JVM in KDE plasma you need to open up terminal and edit ~/.config/mimeapps.list
.
Doing this will change the system defaults for Java-based applications.
Under section
[Default Applications]
I've added the following line to get the desired result:
image/jpg=org.kde.gwenview.desktop;
Upvotes: 1