Run application in minimized state from Java

This is the next question to the one I asked earlier:

start-program-if-not-already-running-in-java

I did not get a great solution there (since it looks like it is not alone), but I have a related question:

Is it possible to run the application in Java code (.exe on Windows, and not in the Java application) and run it with a minimum value? Or perhaps minimize it right after the start? This would solve the focus problem from another question, and an already running problem would more or less cope with itself.

Problems with clarifications again: The Java client and .exe work on Windows, and I really have no way to write any wrappers or use the JNI mojo or something like that. I more or less need a clean Java solution.

Again, thanks for the help, and I'm more than ready to accept an answer that is simple: "It's just not possible."

+4
source share
3 answers

Windows only:

public class StartWindowMinimized { public static void main(String[] args) throws IOException { if (args.length != 1) { System.err .println("Expected: one argument; the command to launch minimized"); } String cmd = "cmd.exe /C START /MIN "; Runtime.getRuntime().exec(cmd + args[0]); } } 

Sample Usage:

 java -cp . StartWindowMinimized notepad.exe java -cp . StartWindowMinimized cmd.exe 

To understand the arguments:

 cmd /? START /? 
+9
source

I am not familiar with Java specifics, but according to the website I just looked at, if you use java.awt.Frame (which includes Swing's JFrame), you should use the off function of this frame called setState, which accepts Frame.ICONIFIED and Frame.NORMAL as a parameter (the minimized state will be indicated).

How to minimize Java application window?

0
source

If these applications have command line switches so that they can be minimized, you can easily use them. Otherwise, I can’t be 100% sure, but I really doubt that this is possible. You must have some way of interacting with the Windows window manager, which in its essence is very specific to the platform, so Java is unlikely to enable it. It is always possible that someone wrote a third-party library to handle the task, but it just doesn't seem to me.

0
source

All Articles