你能把JFrame放在全屏独占模式吗? [英] Can you put JFrames inside Full Screen Exclusive Mode?

查看:141
本文介绍了你能把JFrame放在全屏独占模式吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说实话,我不太清楚如何在标题中表达我的问题。因此,如果有人对我想要提出的问题有了更清楚的认识,那么请为编辑它而感到亲切,为了人类的更大利益。

To be honest, I didn't quite know how to express my question in the title. So if someone has a clearer idea of what i'm trying to ask, then please be so kind as to edit it, for the greater good of mankind.

我有以下代码:

public class Main {
  public static void main(String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();

    JFrame frame = new JFrame();
    Window window = new Window(frame);

    JButton btn = new JButton("Quit");
    window.add(btn);

    if(gd.isFullScreenSupported())
        gd.setFullScreenWindow(window);

    btn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
            GraphicsDevice gd = ge.getDefaultScreenDevice();
            gd.setFullScreenWindow(null);
        }
    });
}

}

我想做的是制作一个以全屏模式说明的图书馆系统。在全屏模式下,应该有简单的框架窗口,里面有文本字段等等......这里不需要沉重的2D / 3D图形......

What I want to do is make a library system, illustrated in full screen mode. Inside the full screen mode, there should be simple frame windows with text fields in them and so on... No heavy 2D/3D graphics required here...

My问题是,退出按钮的大小调整以适应整个屏幕。我试图在框架,窗口甚至按钮上使用setBounds,setSize等......但它似乎并没有让我能够将按钮置于中间位置。

My problem is, the quit button is resized to fit the entire screen. I've tried to use setBounds, setSize, etc, on the frame, window and even button... But it doesn't seem to let me be able to center the button in the middle.

所以我的问题:是否可以在JFrame应用程序窗口中设置JFrame应用程序窗口,该窗口设置为全屏独占模式?或者只能使用全屏独占模式和绘图等2D / 3D方法?

So my question: Is it possible to make JFrame application windows inside a JFrame application window which is set to full screen exclusive mode? Or is it only possible to use full screen exclusive mode together with 2D/3D methods like drawing?

注意:我打算使用全屏模式的唯一方法是将其设置为黑色背景,并在应用程序中心的此黑色背景上有一个Jframe窗口。这是假设应用程序实际上是一个系统。

Note: The only thing I intend to use full screen mode for is to set it to a black background, and have a Jframe window ontop of this black background in the center of the application. It is to give the illusion that the application is actually a system.

谢谢。

P.S。请注意,退出按钮仅用于我自己的测试目的。它不会是实际系统的一部分,所以我的问题不在于如何调整这个特定的退出按钮的大小。

P.S. please note that the quit button was merely for my own testing purposes. It won't be part of the actual system, so my question does not revolve around how to resize this particular quit button.

推荐答案

全屏独占模式并不意味着内置Swing组件。它是一种用Java绘制图形的高性能方式(如果做得好,可以尽可能多地利用底层硬件)。

Fullscreen Exclusive Mode is not meant to have Swing components inside. It is meant as a high performance way to draw graphics in Java (and can benefit as much as possible of underlaying hardware if done right).

你想做什么可以通过使用未修饰的 JDesktopPane 并最大化它超过了屏幕的尺寸。然后继续使用 JInternalFrame 进行操作JFrame就像JDesktopPane里面的窗口。

What you want to do could be done by using an undecorated JDesktopPane and maximize it over the dimensions of the screen. Then proceed with using a JInternalFrame to have a JFrame like window inside that JDesktopPane.

我已经包含了各个API部分的链接,它们应该可以帮助你开始。

I've included links to the respective API sections, they should get you started.

这篇关于你能把JFrame放在全屏独占模式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆