0

I have done a bunch of research and I have looked through many examples but I cannot figure out why my code is not working. I am attempting to make a window full screen(no toolbars or anything, ACTUAL full screen) and have been playing around with the code: (from http://docs.oracle.com/javase/tutorial/extra/fullscreen/exclusivemode.html)

EDIT: People are not getting it. Im quite confident that this code below, does what i want it to, sets the frame full screen. Its just not working for me! Telling me to use .setExtendedState(JFrame.MAXIMIZED_BOTH) is not what im looking for.

GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
                GraphicsDevice dev = env.getDefaultScreenDevice();
                System.out.println(dev.isFullScreenSupported());
                dev.setFullScreenWindow(frame);

I dont fully understand what the code does but i know it is not making my window full screen. i have looked through other examples and this seems to be the way to do it. This is the rest of my code(so far, im just starting a new project):

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

public class Main extends JFrame {

private JPanel contentPane;

/**
 * Launch the application.
 */
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                Main frame = new Main();

                frame.setResizable(false);
                frame.setUndecorated(false);
                frame.setVisible(true);
                GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
                GraphicsDevice dev = env.getDefaultScreenDevice();

                //this returns true
                System.out.println(dev.isFullScreenSupported());

                dev.setFullScreenWindow(frame);
                frame.validate();

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the frame.
 */
public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    contentPane.setLayout(new BorderLayout(0, 0));
    setContentPane(contentPane);
 }
}
Tim E
  • 1
  • 3
  • Have you tried my answer? – Raja Anbazhagan Jan 20 '16 at 01:01
  • Yes, it works, but doesnt do what i want. see ( http://stackoverflow.com/questions/7456227/how-to-handle-events-from-keyboard-and-mouse-in-full-screen-exclusive-mode-in-ja/7457102#7457102) – Tim E Jan 20 '16 at 01:14
  • So what do you want other than full screen? – Raja Anbazhagan Jan 20 '16 at 01:22
  • 1
    Works okay for me, Windows 10, Java 8. What OS/Java version are you using? – MadProgrammer Jan 20 '16 at 02:07
  • Just to avoid confusions, You need a full screen swing window without no taskbar and titlebar right? – Raja Anbazhagan Jan 20 '16 at 12:07
  • The code actually works. What you are looking for is called "[exclusive fullscreen](https://docs.oracle.com/javase/tutorial/extra/fullscreen/)", while "maximized both... and so on" creates a maximized window. In exclusive mode you are able to change the resolution and paint in a fast way, by suspending the window manager. – Stefan Jan 20 '16 at 14:43
  • @MadProgrammer that code works? Thats really wierd. Im totally stumped now. Windows 8.1 not sure of java version but i have got other examples to work using the same code, just not this one -_- – Tim E Jan 20 '16 at 14:44

0 Answers0