【发布时间】:2012-10-05 18:04:46
【问题描述】:
如何在 Mac 上的 Eclipse 中创建一个JFrame 窗口,该窗口有一个使窗口全屏显示的图标,就像大多数窗口右上角的双箭头图标一样??
【问题讨论】:
如何在 Mac 上的 Eclipse 中创建一个JFrame 窗口,该窗口有一个使窗口全屏显示的图标,就像大多数窗口右上角的双箭头图标一样??
【问题讨论】:
看看
更新
你很幸运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();
}
}
}
【讨论】:
Window 设置的经验,我认为它会 ;)