Search code examples
javaswingjar

Force System Properties in a JAR


I currently had a problem similar to this previous question:

Why would our Java app not display windows on secondary monitor?

The answer was to include:

  • Dsun.java2d.d3d=false
  • Dsun.java2d.noddraw=true

So I created my shortcut to launch the application as such:

C:\WINDOWS\system32\javaw.exe -Dsun.java2d.d3d=false  -Dsun.java2d.noddraw=true -jar <file name>

Is there anyway to force that application to use that in code and not have to use parameters?


Solution

  • Yes, you can use System.setProperty(property, value); at the beginning of your program. Eg:

    public static void main(String[] args)
    {
        System.setProperty("sun.java2d.d3d", "false");
        System.setProperty("sun.java2d.noddraw", "true");
    
        // Start your real application
    }