is it possible to start a java application with an argument that sets the window position and target screen index?
I run my java project using IntelliJ and want it to start on the secondary screen. Currently I always have to drag it on my own every time I run the application. This is annoying because the window size is higher than the first screen size.
Thank you.
Related
I am well aware with the setAlwaysOnTop javafx method which can bring the stage in front when clicked on the application. But the problem is that with setting setAlwaysOnTop to be true , the window appears always on top of other windows irrespective of whichever window we open . Even if I open chrome or firefox or any other window , my java fx application window would still lie on the top.
I want it to adjust the z value in order that it gets changed depending upon which window is currently being opened .
Instead of always setting the z value to be maximum , I want the z order to be adjustable .
Can anyone tell me how to do that.
I have built a window application using the SWT WindowBuilder in Eclipse. I want the window to be a set size whilst the application is running.
This means that I do not want the user to be able to resize the window e.g. disable window resizing and if that is not possible then I would like to ensure that the window has a maximum size (this is called bounds in Eclipse).
Looking at the official documentation I cannot find a setMaximumSize. Only a setMinimumSize (which I have already specified).
Official documentation link
Is there a way of getting the size of the window if it changes (such as an event handler). If there is how would I use an event handler to monitor size and change the size back to 300,600 if it were to change?
I only want the window size to be 300 width and 600 height. IS THAT TOO MUCH TO ASK!? :'(
How could I go about setting an infinite loop to constantly set the dimensions? What would the impact of this be on the performance of the application?
When a new monitor is added to a PC or a laptop that's already running a JRE instance, we find that the monitor just added is not considered an extension of a larger virtual screen, but rather JRE creates two separate virtual screens (each with (0,0) as the upper left coordinate as indicated by the GraphicsConfiguration associated the list of devices retrieved using getScreenDevices()). Restarting the JRE fixes the problem (i.e., the two screens are now treated as part of a larger virtual screen with separate starting coordinates).
My question is: How do you correctly determine the monitor (GraphicsDevice) instance where a Java Applet is currently displayed under the following circumstances:
1. The user adds a monitor to his PC/laptop
2. User drags the browser window running the Applet and repositions it in the new screen.
3. Any JDialog or other frames need to open in the new screen, but this can only be done if we can automatically detect the screen instance where the Applet was repositioned.
As mentioned earlier, simply checking the position of the Java Applet against the bounds of the graphics configuration of the various screens does not work, as the bounds all start at (0,0).
I don't want my users or customers to have to kill and restart their Java.exe just because a new monitor was added so that screen instances can be correctly melded by JRE into a single Virtual Screen. Any ideas?
I am working on a Java application which has to launch a different application. If I launch the second application using Runtime.getRuntime().exec(), it becomes the active process and its window comes before my application's window. What I really want to do is launch the process in "hidden" mode so that its taskbar entry does not appear and its window is initially invisible or behind my application window. Then my application would make it visible or move it to the front when it is good and ready. Is this possible or am I asking for too much?
This is for a demo. So I am not worried about security issues.
Edit: Daniel's answer has given me an idea. What if I use Powershell to invoke the application instead of CMD.EXE? Will that let me start the app without the window and then bring the window back? I will be using to launch java to launch PowerShell to launch app, but what the heck!
You don't say what this other application is, but I'm assuming that it's one that you have no control over (i.e. you can't give it a parameter option to start up in a minimized mode or similar.) Rather than hide the application you're launching, can you just use the toFront() method on your window after the other application has launched to bring your window in front of the other? And then minimize your window when you want to reveal the other one?
I'm the first to admit it's a bit of a bodged solution, but it might work depending on what you're after.
You cannot provide these parameters, BUT you can use the "start" command (try it in cmd), which supports these parameters. Eventually you have to call it with a cmd.exe shell, but this will work!
I'm developing a Swing-based Java application in Eclipse on Windows XP. I have a dual monitor setup.
I want to have the program launch on a different monitor than the one I'm running Eclipse in. How can I set up my Debug Configuration to make this happen?
When a new frame is opened, it defaults to coordinates 0,0. Exactly where this is depends on your operating system's monitor layout. Typically, 0,0 will be the upper-left corner of the primary monitor.
The solution to your problem is to run Eclipse on your secondary monitor, so that the applications will open on the other (primary) monitor. You don't actually have to move Eclipse to do this. Go into your operating system's monitor settings and switch the primary monitor to the monitor you wish to start the application on. Eclipse will now be running on the secondary monitor.
Your new frame will now be opened on the other monitor, and you have changed no code in the process, just your operating system's configuration settings.
It depends a bit how you did set up your second monitor. For my answer, I'm assuming that you added it as an "extension" to your desktop (so you can move windows between them by dragging with the mouse).
In this mode, your desktop becomes bigger. To see that, call GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds.
The width should be the sum of the widths of your two monitors and the height should be the larger of the two heights.
Note that the x coordinate can be < 0 (this happens if your make the right monitor the default one).
To move your window to the other monitor, simply use a position (setPosition()) with an appropriate value and pass that position as an option to the program. Or save the current position as a preferences node and open the window again in the same place when the app is run again.
If your monitors are configured independently, you should look into the GraphicsEnvironment.getScreenDevices() API.
I think you can't do that. The only solution I found is to move the program from the first display to the second one manually and then close it in this position (with the close button and not the Console terminate red button that stop brutally the VM without saving anything). Then on the next restart, your program launch should appear on the second display. In order to have this solution working, your launch configuration should not clear the workspace and the config at each launch in order to keep the programm screen location.
See RCP opening monitor for related stuff on RCP app.
You can probably achieve that behavior programmatically. I'm sure you can Google and find examples of how to open your window on the second monitor. If it is something you want only at debug-time, add a switch in your launch configuration (more specifically, a JVM runtime argument) and check for the switch (System.getProperty) when your program starts.