0
How can I put a Jframe in full screen and change the screen resolution using:
device.setDisplayMode(new DisplayMode(Width,Height,16,DisplayMode.REFRESH_RATE_UNKNOWN));
I must use a new library?
Thanks
0
How can I put a Jframe in full screen and change the screen resolution using:
device.setDisplayMode(new DisplayMode(Width,Height,16,DisplayMode.REFRESH_RATE_UNKNOWN));
I must use a new library?
Thanks
1
It is very likely that your video card or your video driver can’t stand it the change, especially if your driver is generic, for example this using a newer operating system than your graphics card, for example in my case the video only provides 32bit, this may be due to board (Onboard) or because I installed Window 8.1 for an older board, which only supports Windows7.
To know which modes your system do the following way (if you use Windows):
This will turn up:
Note that all "modes" only have support for 32 bits
, I think using 16bits nowadays is unnecessary
From what I read, modern systems don’t need more than 16bits, or anything less than 32bits, there are techniques (which probably only programs with administrator accesses can use), one of them is to put the program to start with compatibility mode, however the process is all manual and can not do this by Java (except if it is a scam using the Windows Apis), for example:
To make sure it supports you can test the function:
GraphicsDevice.isDisplayChangeSupported
And in the setDisplayMode
use Try/catch:
try {
device.setDisplayMode(displayMode);
} catch (Throwable e) {
//Pega o erro e.getMessage
}
Now to leave the JFrame
in fullscreen, regardless of the support of your video card and/ or driver you can use so:
frame.setExtendedState(JFrame.MAXIMIZED_BOTH); //Maxmiza
frame.setUndecorated(true); //Remove a decoração da janela
This will leave your JFrame
in fullscreen, but it does not mean that it will change the screen resolution.
It should look like this (press Alt+F4 to close):
Note: added the
javax.swing.JOptionPane
only to display messages to know what happened
import java.awt.DisplayMode;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class Main
{
public static void main(String[] argv) throws Exception
{
final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
final GraphicsDevice device = ge.getDefaultScreenDevice();
final int width = 640;
final int height = 480;
if (device.isDisplayChangeSupported()) {
final DisplayMode displayMode = new DisplayMode(width, height, 16, DisplayMode.REFRESH_RATE_UNKNOWN);
try {
device.setDisplayMode(displayMode);
JOptionPane.showMessageDialog(null, "Mudou a resolução");
} catch (Throwable e) {
device.setFullScreenWindow(null);
JOptionPane.showMessageDialog(null, e.getMessage());
}
} else {
JOptionPane.showMessageDialog(null, "Sem suporte para mudar a resolução");
}
final JFrame frame = new JFrame("Minha primeira janela");
frame.setExtendedState(JFrame.MAXIMIZED_BOTH); //Maxmiza
frame.setUndecorated(true); //Remove a decoração da janela
frame.setVisible(true);
}
}
Browser other questions tagged java swing fullscreen
You are not signed in. Login or sign up in order to post.
I did not understand what the problem is. It could be more specific?
– gato
What do you mean "Full screen in 16bit"?
– gato
You’re using the Swing?
– Victor Stafusa
Ta on when you use Graphicsdevice to defnir which Jframe will be displayed in full screen and/or change the screen resolution? In this case, I want to change the screen resolution and set it Coo 16 Bits Yes, I am using Swing for Jframe and java.awt for Graphicsdevice
– Josesk Volpe
What is this device variable? Add the rest of the code to make it easier to understand.
– user28595
@cat he probably talks about this https://i.stack.Imgur.com/mSRuW.jpg, the video drivers used to reach up to 16bit, then came better technologies (like 24bit and 32bit), however the 16bit mode was maintained, it refers to the color capacity that a driver has. 16 = 65,536 colours, 24 = 16,777,215 and 32 = 4,294,967,296... The author’s intention when using 16bit may be to create a game (or something else) that does not require as many colors... PS: Josesk today some cards do not support use less than 32bit, probably so no script will work, it will continue 32bit.
– Guilherme Nascimento
Yes exactly what I’m talking about :3 vlw
– Josesk Volpe
Josesk came to read the answer after I edited it?
– Guilherme Nascimento