How to have a JFrame Maximise icon

余生颓废 提交于 2019-12-12 07:08:49

问题


How do i create a JFrame window in eclipse on a Mac that has an icon that makes the window full screen like the double arrow icon on most windows at the top right??


回答1:


Take a look at

  • Fullscreen feature for Java Apps on OSX Lion
  • And Java Runtime System Properties, which may be of interested
  • or How can I do full screen in Java on OSX if those were the wrong feature you wanted

UPDATE

Lucky for you JFrame extends Window via Frame...

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


来源:https://stackoverflow.com/questions/12751704/how-to-have-a-jframe-maximise-icon

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!