0

Just wondering how I would make the java applet be fullscreen when I run it. I don't want to manually do it with a setSize(); command. I was trying to get it so It would go fullscreen on any monitor regardless of the dimensions. Was just curious if this was possible in eclipse and if so how would I go about doing it.

  • 1
    Since an applet runs inside the context of the browser, it is restricted to the size allocated to it by the browser - besides, applets are dead, seriously time to move on. – MadProgrammer May 16 '18 at 00:45
  • 1
    When you talk about "full screen", you need to understand that it has different meanings to different people, based on OS and other context. For example, do you mean ["maximised"](https://docs.oracle.com/javase/8/docs/api/java/awt/Frame.html#setExtendedState-int-) or do you mean ["Full Screen Exclusive Mode"](https://docs.oracle.com/javase/tutorial/extra/fullscreen/index.html), which in the case of [MacOS could mean something different](https://stackoverflow.com/questions/30089804/true-full-screen-jframe-swing-application-in-mac-osx/30090377#30090377) – MadProgrammer May 16 '18 at 00:47
  • I meant maximized, im on windows using Eclipse. – Alex Suero May 16 '18 at 00:56
  • Then simply use [`JFrame#setExtendedState`](https://docs.oracle.com/javase/8/docs/api/java/awt/Frame.html#setExtendedState-int-) and pass it `JFame. MAXIMIZED_BOTH` – MadProgrammer May 16 '18 at 00:58

1 Answers1

0

I meant maximized, im on windows using Eclipse

Then simply use JFrame#setExtendedState and pass it JFame.MAXIMIZED_BOTH

As an example...

import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class Test {

    public static void main(String[] args) {
        new Test();
    }

    public Test() {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                    ex.printStackTrace();
                }

                JFrame frame = new JFrame("Testing");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.add(new JLabel("I'm a happy bunny"));
                // The following two lines just set up the
                // "default" size of the frame
                frame.pack();
                frame.setLocationRelativeTo(null);
                frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
                frame.setVisible(true);
            }
        });
    }

}
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366