java - 我无法使用 FullscreenWindow 看到我的窗口

标签 java swing fullscreen

一切都是黑色的。

btnFullScreen.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent event) {
                GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
                GraphicsDevice gd = ge.getDefaultScreenDevice();
                if (gd.isFullScreenSupported()) {
                    gd.setFullScreenWindow(frame);
                }
            }
        });

最佳答案

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

gd.setFullScreenWindow(frame); 函数要求在此函数调用之前框架不可见:

来自documentation :

When entering full-screen mode, if the window to be used as a full-screen window is not visible, this method will make it visible. It will remain visible when returning to windowed mode.

When entering full-screen mode, all the translucency effects are reset for the window. Its shape is set to null, the opacity value is set to 1.0f, and the background color alpha is set to 255 (completely opaque). These values are not restored when returning to windowed mode.

It is unspecified and platform-dependent how decorated windows operate in full-screen mode. For this reason, it is recommended to turn off the decorations in a Frame or Dialog object by using the setUndecorated method.

有什么问题:jFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);

编辑:一个演示来支持我的主张,这就是我们所说的 SSCCE 我也有一个按钮,框架被最小化为按钮的大小。单击按钮查看 setExtendedState(JFrame.MAXIMIZED_BOTH) 函数的操作。

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class MyWindow extends JFrame
{
    int width=GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().width;
    int height=GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().height;
    public MyWindow ()
    {

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JButton button = new JButton("Click Me");
        button.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
               setExtendedState(JFrame.MAXIMIZED_BOTH);
            }
        });

        add(button);
        pack();

    }

    public static void main(String[] args)
    {
        new MyWindow().setVisible(true);

    }
}
<小时/>

编辑:来自您的以下评论:

Yes,but i want fullscreen,because my application already obtains to be maximized.

您可能正在使用以下函数:jFrame.setUndecorated(true);,它将删除标题栏和所有内容以使框架包含全屏。

关于java - 我无法使用 FullscreenWindow 看到我的窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19986792/

相关文章:

java - JFrame 未显示

java - SQL注入(inject): want to show a demo of sql injection

java - 获取哪个Jframe打开了另一个Jframe

java - 如何从头开始创建 RTF 编辑器(使用 Java)

java - repaint 方法一旦调用就什么都不做

背景大小 :cover leaves blank space in Chrome for Android

ios - 应用程序在 UIViewController : com. apple.main-thread 中的用户设备上崩溃

javascript - 全屏视频 HTML 5 Internet Explorer

java - Okhttp java.net.ProtocolException : unexpected end of stream

java - 学习JAVA需要帮助理解getLogger().info()(Method Chaining)的概念