如何让java小程序自动全屏? (蚀)

How to make java applet auto fullscreen? (Eclipse)

只是想知道如何在 运行 时让 java 小程序全屏显示。我不想使用 setSize(); 命令手动执行此操作。我试图得到它,这样它就可以在任何显示器上全屏显示,而不管尺寸如何。只是好奇这在 eclipse 中是否可行,如果可以,我将如何去做。

I meant maximized, im on windows using Eclipse

然后简单地使用JFrame#setExtendedState并传递它JFame.MAXIMIZED_BOTH

举个例子...

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);
            }
        });
    }

}