gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 13:50:40 24 4
gpt4 key购买 nike

一切都是黑色的。

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/

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