I'm working on a fullscreen application and discovered some really weird behavior using setFullScreenWindow(Frame) to actually get the application frame to fullscreen exclusive mode on some notebooks. While my code works on most WinOS systems on some it just doesn't. The resolution change works but the application stays in the top left corner of the screen in its former resolution like the setFullScreenWindow(Frame) call did not actually work. No exception thrown. If I connect a second display to the system and make it primary display it suddenly works. If I disconnect the second display and run the app on the previous used native display it also now suddenly works. If I reboot the system the native display again fails to bring the app to fullscreen. Both isFullScreenSupported() and isDisplayChangeSupported() are true in any cases.
Strange. Notebook is a MacBookPro with a Bootcamp WinOS10 installation but problem is not limited to this hardware or WinOsVersion.
client.windowScale = 2;
client.setVisible(false);
client.setResizable(false);
client.setUndecorated(true);
client.setSize(RES_WIDTH * client.windowScale, RES_HEIGHT * client.windowScale);
DisplayMode newDisplayMode;
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
DisplayMode_Old = gd.getDisplayMode();
if (gd.isFullScreenSupported() & gd.isDisplayChangeSupported()) {
gd.setFullScreenWindow(client);
gd.setDisplayMode(
new DisplayMode(
RES_WIDTH * client.windowScale,
RES_HEIGHT * client.windowScale,
DisplayMode_Old.getBitDepth(),
DisplayMode_Old.getRefreshRate()));
}
else {
System.out.println("Fullscreen failed.");
}
}
Actual Image:
Related
I recently ran into an issue that I cannot explain. Hopefully someone knows what I can do to resolve my issue. I have a dual monitor machine running Windows 7 64-bit. Both monitors are identical models and settings. The primary monitor is on the right. I am using JRE 1.8.0_131
The issue I am seeing is that recently I discovered I am no longer able to run my Java Swing application on my second monitor. This was working perfectly fine before, as in I could move my application between both monitors, resizing and switching to/from maximized with no problems. Now whenever my application is on my second monitor, all I see is a frame that shows the part of my desktop background that is behind the frame
Below is a small sample program that creates a frame for each monitor. The frame on my primary monitor looks fine. The one on my secondary monitor is messed up like I mentioned. Simply moving the bad frame to my primary monitor does nothing to fix it but if I minimize then restore it looks fine (i.e. if I force the frame to repaint on the primary monitor it looks fine). Similarly, moving the good frame to the secondary monitor and forcing a repaint results in the bad frame
My JRE has not been updated in months so that does not seem like the issue. As an experiment I tried using JDK 1.7.0_17 but it has the same results. My machine got a Windows update yesterday which maybe coincidentally is when I noticed this issue. I am not saying that is the issue, just noting the information I have
Anyhow, any thoughts or suggestions would be greatly appreciated. This issue is annoying since dual monitor support is helpful for having my application and Eclipse visible at the same time, as well as the fact that my application has multiple frames which I placed one per monitor
SwingUtilities.invokeLater(new Runnable()
{
#Override
public void run()
{
for (final GraphicsDevice device : GraphicsEnvironment
.getLocalGraphicsEnvironment().getScreenDevices())
{
final DisplayMode displayMode = device.getDisplayMode();
LOGGER.debug(
"testSwing: device: {}, ID string: {}, isFullScreenSupported: {}, "
+ "displayModeWidth: {}, displayModeHeight: {}, "
+ "displayModeBitDepth: {}, displayModeRefreshRate: {}", device,
device.getIDstring(), device.isFullScreenSupported(),
displayMode.getWidth(), displayMode.getHeight(), displayMode.getBitDepth(),
displayMode.getRefreshRate());
if (GraphicsDevice.TYPE_RASTER_SCREEN == device.getType())
{
final GraphicsConfiguration configuration =
device.getDefaultConfiguration();
final JFrame frame = new JFrame("Test Frame", configuration);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(
new JLabel(device.getIDstring(), SwingConstants.CENTER));
final Rectangle screenBounds = configuration.getBounds();
frame.setBounds((screenBounds.x + (screenBounds.width / 2)) - 100,
(screenBounds.y + (screenBounds.height / 2)) - 100, 200, 200);
frame.setVisible(true);
}
}
}
});
NOTE: LOGGER is just a SLF4J logger which I added only to see if there was any useful information I could gather. This can be removed when running as it has no effect on the issue described above
Output from running this on my machine:
testSwing: device: Win32GraphicsDevice[screen=0], ID string: \Display0, isFullScreenSupported: true, displayModeWidth: 1920, displayModeHeight: 1200, displayModeBitDepth: 32, displayModeRefreshRate: 59
testSwing: device: Win32GraphicsDevice[screen=1], ID string: \Display1, isFullScreenSupported: true, displayModeWidth: 1920, displayModeHeight: 1200, displayModeBitDepth: 32, displayModeRefreshRate: 59
It is happening because moving your application has contents which is not updating when it is moving to another monitor and still trying to get data from initial monitor.
Try this link. Its about displaying JFrame on multiple monitors. Hope this will help.
how to display JFrame in full screen display mode at a multi-monitor environment?
I've got a Java swing program that runs in full screen mode. It's effectively a kiosk program in that I want it to lock out everything else while it's running. This is running on a Windows 8.1 tablet, so of course the tablet is touchscreen, and therefore if you do an "edge swipe" (drag your finger from the right) the charms bar pops up and you can get to the Start screen from there. Is there some way to disable this from happening in Java? (Or is there some third-party solution not involving Java that can work in tandem to achieve the same result?)
You can disable edge gestures while your app is active and full screen by setting the System.EdgeGesture.DisableTouchWhenFullScreen property on the window.
I don't know if Java provides a direct way to set this (probably not), but you should be able to set this from a JNI.
Here's a C++ snippet from the DisableTouchWhenFullScreen docs:
HRESULT SetTouchDisableProperty(HWND hwnd, BOOL fDisableTouch)
{
IPropertyStore* pPropStore;
HRESULT hrReturnValue = SHGetPropertyStoreForWindow(hwnd, IID_PPV_ARGS(&pPropStore));
if (SUCCEEDED(hrReturnValue))
{
PROPVARIANT var;
var.vt = VT_BOOL;
var.boolVal = fDisableTouch ? VARIANT_TRUE : VARIANT_FALSE;
hrReturnValue = pPropStore->SetValue(PKEY_EdgeGesture_DisableTouchWhenFullscreen, var);
pPropStore->Release();
}
return hrReturnValue;
}
What I ended up doing was to write a batch script that kills explorer.exe and then re-spawns it after the app exits, based on this answer on Super User.
I am trying to make my java slick2d game fullscreen capable. It launches into fullscreen fine initially with this code:
Container app = new Container(this);
DisplayMode current = Display.getDesktopDisplayMode();
System.out.println(current.getWidth() + "x" + current.getHeight());
Start.setFullscreen(current.getWidth(), current.getHeight());
app.setDisplayMode(Start.FULLSCREEN_WIDTH, Start.FULLSCREEN_HEIGHT, true);
app.setResizable(true);
app.setTargetFrameRate(60);
app.setClearEachFrame(true);
app.setAlwaysRender(false);
app.start();
(The Start class holds a few constant variables that the rest of the program references)
I can also turn off fullscreen in my update method with this code:
if (gc.getInput().isKeyPressed(Input.KEY_ESCAPE)){
if (gc.isFullscreen()){
gc.setFullscreen(false);
} else {
AppGameContainer app = (AppGameContainer)gc;
app.setDisplayMode(Start.FULLSCREEN_WIDTH, Start.FULLSCREEN_HEIGHT, true);
}
}
When I run the program and press escape, it becomes a window and looks fine but when I try to put it back into fullscreen mode, it occupies the whole screen but there is a black bar at the top of the window and the displaying area is squished to whatever size the window was. Here is a screenshot of this effect:
Also, when I switch to fullscreen the console prints INFO:Starting display 1440x900 which is the correct screen size of my display.
I am using a MacBook Air 13-inch running 10.9.2 (Mavericks).
How to use Vesa Video mode in Java?
You can have java run as a full screen app, aka exclusive mode.
DisplayMode oldDisplayMode = myDevice.getDisplayMode();
try {
myDevice.setFullScreenWindow(myWindow);
myDevice.setDisplayMode(newDisplayMode);
...
} finally {
myDevice.setDisplayMode(oldDisplayMode);
myDevice.setFullScreenWindow(null);
}
You can also change the display mode. If the device supports the Vesa modes, then it may be in the list of available modes in Java.
See Sun Tutorial - Full Screen Exclusive Mode
I am designing a psychology experiment with java applets. I have to make my java applets full screen. What is the best way of doing this and how can I do this.
Since I haven't been using java applets for 3 years(The last time I've used it was for a course homework :) ) I have forgotten most of the concepts. I googled and found that link:
Dani web
But in the method described in above link you have to put a JFrame inside the applet which I have no idea how to do it.
Whatever I need a quick and dirty method b'cause I don't have much time and this is the reason why I asked it here.
Thanx in advance
The obvious answer is don't use applets. Write an application that uses a JFrame or JWindow as its top-level container. It's not a huge amount of work to convert an applet into an application. Applets are designed to be embedded in something else, usually a web page.
If you already have an applet and want to make it full screen, there's two quick and dirty hacks:
1). If you know the screen resolution, just set the applet parameters to be that size in the HTML and then run the browser in full screen mode.
2). Run the applet in appletviewer, rather than a web page, and maximise the appletviewer window.
Why not just open a new Frame from the applet (either from the "start()" method or, preferably, after the user presses an "open" button) and set it to be maximized?
JFrame frame = new JFrame();
//more initialization code here
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
frame.setSize(dim.width, dim.height);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
Don't forget: The JFrame should be created and opened from the EDT. Applet start() is not guaranteed to be called on that thread, so use SwingUtilities.invokeLater(). Of course, if you opt for the button route, button listener is called on the EDT, so you should be safe.
I think you want to use WebStart. You can deploy from a browser but it is otherwise a full blown application. There are a few browserish security restrictions, but, as you're using an Applet currently, I think I can assume they're not a problem.
I've found a solution for this problem that works fine. Tested in Linux 64 bits (Chrome and Firefox) and in Windows 7 64 bits (Chrome and Explorer)
The only problem has been that my applet uses all the space in the browser and when the user switch off the full screen mode, the applet is not scaled to the browser size. The solution has been to keep the previous size of the applet before to enter in a fullscreen mode and then, set this size when the applet returns to the normal mode:
public void setFullScreen() {
if (!this.fullscreen) {
size = this.getSize();
if (this.parent == null) {
this.parent = getParent();
}
this.frame = new Frame();
this.frame.setUndecorated(true);
this.frame.add(this);
this.frame.setVisible(true);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] devices = ge.getScreenDevices();
devices[0].setFullScreenWindow(this.frame);
this.fullscreen = true;
} else {
if (this.parent != null) {
this.parent.add(this);
}
if (this.frame != null) {
this.frame.dispose();
}
this.fullscreen = false;
this.setSize(size);
this.revalidate();
}
this.requestFocus();
}