【问题标题】:How to have a JFrame Maximise icon如何有一个 JFrame 最大化图标
【发布时间】:2012-10-05 18:04:46
【问题描述】:

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

【问题讨论】:

    标签: java swing jframe


    【解决方案1】:

    看看

    更新

    你很幸运JFrame 通过Frame 扩展Window...

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

    【讨论】:

    • 这似乎是我正在寻找的(第一个),但我在实现它时遇到了一些麻烦。我在java方面相当新。该函数需要一个窗口,但我如何从 JFrame 中获取一个窗口?
    • 谢谢你,我的代码没有工作,因为我在调用全屏方法之前有 setVisible。显然它需要隐藏窗口才能执行操作。
    • 不确定,但鉴于我对其他 Window 设置的经验,我认为它会 ;)
    猜你喜欢
    • 2014-01-02
    • 1970-01-01
    • 2014-07-10
    • 2011-07-12
    • 1970-01-01
    • 2010-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多