我正在尝试在基于此代码的 Java APP 中实现全屏模式
private static void createAndShowGUI()
{
//Create and set up the window.
JFrame frame = new JFrame("Mouse Click Demo");
//Make it non-Resizable
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane.
JComponent newContentPane = new MouseEventDemo();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);
//Display the window.
frame.pack();
//frame.setVisible(true);
if (!frame.isDisplayable())
{
// Can only do this when the frame is not visible
frame.setUndecorated(true);
}
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
try
{
if(gd.isFullScreenSupported())
{
gd.setFullScreenWindow(frame);
System.out.print("DOES SUPPORT");
}
else
{
//Can't run in full screen mode
System.out.print("DOES NOT SUPPORT");
}
frame.setVisible(true);
}
finally
{
gd.setFullScreenWindow(null);
}
}
问题是,当我在 Macbook 上运行时,它仍然显示顶部 Mac 栏和底部甲板,控制台确实进入状态并打印DOES SUPPORT但仍不显示在全屏模式下。
我在做什么错?
编辑:这是我的屏幕截图