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.
Related
I have an annoying situation when I use my preferred IDE, IntelliJ IDEA Community or Ultimate versions, with two monitors in my job and at home. Simply when I turn on my computer after using in the office where the monitor is located on top of my laptop, in my house, where the monitor is located in the left side of my laptop, the IDEA IDE that is continuing running from where I stopped in my office is still in the Windows toolbar.
However when I click on the IDEA's icon in the toolbar it never turns to active and present in the laptop's or in my left side's monitor. What is that unexpected behavior?
Well, after investigating a bit and doing some experiments I found the solution, you need to right-click the desktop area where this menu will pop-up:
Go and select "Display settings" and you will see that window:
What you see in this "Display Settings" Window is that your monitor's setup now (in your house) is the main laptop monitor in right and your laptop on left. But in your office your monitor was in the top of the screen, isn't it?
Solution:
So what you need to do is to trick Windows and say that your actual monitor is in the top to be able to see the IDEA IDE.
Steps:
Move the monitor number 2, dragging it with the mouse to the top of monitor number 1;
Press the "Apply" button;
You will see IDEA IDE, then drag it to the monitor 1;
Open the "Display Settings" again (right click the desktop and select "Display Settings");
Restore the configuration wished to your monitor, in other words: drag the monitor number 2 to the left side (if your physical monitor is really there).
Warning, that is not all, if in step 3 your cannot find the IDEA you need to change the position of the monitor 2 until you find the IDE.
The explanation for that issue is that Windows' monitor's logical area is not synchronizing with IDEA's positioning system. The IDEA's system does keep the last position where the IDE is, and the Operating System changes are not in synch with that. That potentially can happen also on linux or Macs computers.
Hi I'm working on a group project and the code works on my teammate's PCs but I keep hitting MacOS specific errors. And this time I seem to be stuck (no easily Googleable answer).
In a previous post I discovered I need "-Djava.awt.headless=true" as VM setting to properly run my simulation. Now when I try to spawn in some JFrame they are all met with a lovely "java.awt.HeadlessException" Exception because of that VM flag.
Trying to achieve
I want to be able to spawn those JFrames on my MacBook also.
The problem
I need -Djava.awt.headless to be both true and false at the same time for my program to run properly on Mac. Which if I understand my problem correcly, means I have a big problem on my hands.
EDIT: running it in a VM on my Macbook allowed me to run the project properly. This is far from an ideal fix. I'm still searching for a solution to this obscure problem.
What I tried
not running with the VM option: the problem described in previous post occurs. Thus this is not a viable option
running with the VM option: this throws a -Djava.awt.headless when creating a JFrame.
The best way to fix this may be by going back and solving your original problem a different way.
You must make sure that you are not initializing your BufferedImage in the main thread (GLFW thread), it MUST be done separately. It is hard to tell from your original question, but that looks like part of the cause there. Start a new thread to do the image processing instead.
See my solution and recommendation at the bottom of this answer for a quick summary, and also see here for someone else that had the same issue: Java Creating Instance of BufferedImage Freezes Program
A quick note on why your code works on Windows and not Mac: that is because both OS often run different implementations of openGL, and typically Mac can lag behind and miss out on a bunch of updates/changes that may solve problems like this one so that it doesn’t freeze when initializing a BufferedImage on the openGL thread.
If the above didn’t work then lets first look at what headless mode is. (Emphasis mine):
See link at bottom for full article and more info.
Headless mode is a system configuration in which the display device,
keyboard, or mouse is lacking. Sounds unexpected, but actually you can
perform different operations in this mode, even with graphic data.
Where it is applicable? Let's say that your application repeatedly generates a certain image, for example, a graphical authorization code
that must be changed every time a user logs in to the system. When
creating an image, your application needs neither the display nor the
keyboard. Let's assume now that you have a mainframe or dedicated
server on your project that has no display device, keyboard, or mouse.
The ideal decision is to use this environment's substantial computing
power for the visual as well as the nonvisual features. An image
that was generated in the headless mode system then can be passed to
the headful system for further rendering.
So when should headless mode be used:
On a machine that has no display device, keyboard, or mouse.
That is not you is it? However if that is you (LWJGL?), then lets look at how you can work with headless mode:
An image that was generated in the headless mode system then can be
passed to the headful system for further rendering.
This means that you should have a special piece of headless code that does your headless image stuff, but then passes the image back to a normal JFrame with a head.
So why does it fail for you:
Many components are affected if a display device, keyboard, or mouse
is not supported. An appropriate class constructor throws a
HeadlessException
Button
Checkbox
Choice
Dialog
FileDialog
Frame
Label
List
Menu
MenuBar
MenuItem
PopupMenu
Scrollbar
ScrollPane
TextArea
TextField
Window
Solution to the problem:
some classes, such as Canvas or Panel, can be executed in headless mode.
Perfect, so we just need to be careful what is used in headless mode. You asked how you can both use and not use headless mode, well rather than globally setting headless mode with VM option -Djava.awt.headless you can do it programmatically within your code using System.setProperty("java.awt.headless", "true"); where needed. A JFrame should be normal (not Headless), but you can spawn a JPanel as headless without issue.
I recommend:
You create a normal headed main thread with no VM option that spawns JFrames, and then use that main thread to spawn a new child thread and set your LWJGL bits in that thread to be headless, and that way you can run your LWJGL code without issue, and at the same time you can still have JFrames from your main thread. Remember to make sure that the Buffered image is not done in the main LWJGL/OpenGL thread.
Headless info source:
http://www.oracle.com/technetwork/articles/javase/headless-136834.html
Most 3D applications grab the mouse. This means the OS cursor is hidden and only the 3D application cursor is shown (and only within the application).
In case it is a game, the cursor is completely hidden so you can "look around" moving the camera with the mouse.
While I am debugging with Eclipse IDE or NetBeans IDE, the "grab mouse" event happens.
When a break point is reached, the application will not respond until, thru the IDE, I command it to continue running in the debug mode.
If I manage to make the application continue running I can release the mouse (un-grab, give back the mouse cursor to the OS) by opening a console within the application for example will make it work.
While I have no OS mouse cursor available, I get limited to the keyboard, what make things become really complicated on debugging procedure.
how to work around that?
I found that a simple trick must be used.
Add a watch that evaluates this:
org.lwjgl.input.Mouse.setGrabbed(false)
On eclipse, that watch may require to be visible or its evaluation may be skipped.
here I am looking for an IDE independent way of ungrabbing mouse.
Doing more things than releasing mouse grab:
Later on tho, it did not suffice, I wanted to do more things like auto pause the application and clear keyboard buffer, so, if the breakpoint or exception happens at any code that have no access to the function I created that does it all, that function would not work.
The workaround for that was to create a thread to monitor some variable that should be updated at the main application thread; if that variable is not updated for 1s, call the function to ungrab and etc.
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?
We have a Java/Swing client that's been around for quite a few years. When I moved from XP to Vista (client ONLY runs on Windows), I noticed that whenever a new window is created (usually a JFrame descendant) on my secondary monitor, the window initially shows as blank, i.e. instead of showing the normal contents of the window, it's just a solid block of gray. If I then drag that window onto the primary monitor, the second it crosses the monitor boundary, it draws itself properly and I can drag it back to the secondary monitor. If the window is created on the primary monitor, it always comes into existence perfectly. I NEVER had this problem on XP, only on Vista. I'm unable to easily test it on Windows 7, lacking a dual monitor Windows 7 machine.
Anybody have any ideas? Is this perhaps a known Java bug? I'm also running the most recent Java 1.6 SDK.
Check that the video driver and the JRE are up to date. (It is possible to have a current JDK, but an old JRE.)
Java will delegate the buffering to DirectDraw and/or Direct3D. You can disable this with the following JVM options:
-Dsun.java2d.d3d=false
-Dsun.java2d.noddraw=true
There are other options detailed here.
If the primary monitor is to the right of the secondary monitor, the screen positions on the secondary monitor will have negative X values. (Likewise if the secondary is above the primary positions will have negative Y values.) It is possible there is code that is not handling the negative values.