gpt4 book ai didi

Java Swing : Full Screen mode not working

转载 作者:行者123 更新时间:2023-11-29 05:48:24 24 4
gpt4 key购买 nike

我正在尝试在基于 this code 的 Java 应用程序中实现全屏模式

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 栏和底部 Deck,控制台确实进入状态并打印DOES SUPPORT,但在全屏模式下仍然不显示。

我做错了什么?

编辑:This is my Screen Shot

最佳答案

回应您的Escape评论...

你最好的选择是使用Key Bindings

原因有很多,但最主要的是它不会像 KeyListener 那样受到排他性焦点问题的困扰

public class TickleMe {

public static void main(String[] args) {
new TickleMe();
}

public TickleMe() {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception ex) {
}

final JFrame frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setUndecorated(true);

JPanel content = new JPanel(new GridBagLayout());
content.add(new JLabel("Tickle Me"));
InputMap im = content.getInputMap(JPanel.WHEN_IN_FOCUSED_WINDOW);
ActionMap am = content.getActionMap();
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "getMeOutOfHere");
am.put("getMeOutOfHere", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
try {
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
gd.setFullScreenWindow(null);
} finally {
frame.dispose();
}
}
});

frame.setContentPane(content);

GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
if (gd.isFullScreenSupported()) {
gd.setFullScreenWindow(frame);
frame.requestFocusInWindow();
}

}
});
}
}

关于Java Swing : Full Screen mode not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14950218/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com