0

如何JFrame在 Mac 上的 Eclipse 中创建一个窗口,该窗口具有使窗口全屏显示的图标,就像右上角大多数窗口上的双箭头图标一样?

4

1 回答 1

4

看一眼

更新

幸运的是你JFrame通过......WindowFrame

在此处输入图像描述

public class TestMacFullScreen {

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {

                JFrame frame = new JFrame("Test");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setSize(200, 200);
                frame.setLocationRelativeTo(null);
                frame.setLayout(new BorderLayout());

                JLabel label = new JLabel("Look ma, no hands");

                frame.add(label);

                enableOSXFullscreen(frame);

                frame.setVisible(true);


            }
        });
    }

    public static void enableOSXFullscreen(Window window) {
        try {
            Class util = Class.forName("com.apple.eawt.FullScreenUtilities");
            Class params[] = new Class[]{Window.class, Boolean.TYPE};
            Method method = util.getMethod("setWindowCanFullScreen", params);
            method.invoke(util, window, true);
        } catch (ClassNotFoundException exp) {
            exp.printStackTrace();
        } catch (Exception exp) {
            exp.printStackTrace();
        }
    }
}
于 2012-10-05T19:03:09.240 回答