如何在 Java 中锁定框架 (GUI)

发布于 2024-11-08 16:53:14 字数 162 浏览 0 评论 0原文

我正在启动一个 Java 项目,需要一种方法来完全锁定框架。我所说的锁定是指:

  • 用户无法关闭它
  • 用户无法拖动它
  • 用户无法最小化它
  • 它位于任务栏和其他所有内容的顶部(除非指定)

基本上,它是全屏接管。

I'm starting a Java project and need a way to completely lock down a frame. By lock down I mean:

  • Users can't close it
  • Users can't drag it
  • Users can't minimize it
  • It lies on top of the taskbar and everything else (unless specified)

Basically, it's a full screen takeover.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

早茶月光 2024-11-15 16:53:14

尝试使用全屏独占模式,看看它是否适合您。

Try using fullscreen exclusive mode and see if it works for you.

不寐倦长更 2024-11-15 16:53:14

你可以尝试这样的事情:

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

public class FullScreenTest extends JFrame {

    private GraphicsDevice device;
    private boolean isFullScreen = false;

    public FullScreenTest(GraphicsDevice device) {
        super(device.getDefaultConfiguration());
        this.device = device;
        setTitle("Display Mode Test");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    private void initComponents(Container c) {
        setContentPane(c);
        c.setBackground(Color.RED);
    }

    public void begin() {
        isFullScreen = device.isFullScreenSupported();
        setUndecorated(isFullScreen);
        setResizable(!isFullScreen);
        if (isFullScreen) {
            // Full-screen mode
            device.setFullScreenWindow(this);
            validate();
        } else {
            // Windowed mode
            pack();
            setVisible(true);
        }
    }

    public static void main(String[] args) {
        GraphicsEnvironment env = GraphicsEnvironment.
            getLocalGraphicsEnvironment();
        GraphicsDevice[] devices = env.getScreenDevices();
        FullScreenTest test = new FullScreenTest(devices[0]);
        test.initComponents(test.getContentPane());
        test.begin();
    }
}

You can try something like:

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

public class FullScreenTest extends JFrame {

    private GraphicsDevice device;
    private boolean isFullScreen = false;

    public FullScreenTest(GraphicsDevice device) {
        super(device.getDefaultConfiguration());
        this.device = device;
        setTitle("Display Mode Test");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    private void initComponents(Container c) {
        setContentPane(c);
        c.setBackground(Color.RED);
    }

    public void begin() {
        isFullScreen = device.isFullScreenSupported();
        setUndecorated(isFullScreen);
        setResizable(!isFullScreen);
        if (isFullScreen) {
            // Full-screen mode
            device.setFullScreenWindow(this);
            validate();
        } else {
            // Windowed mode
            pack();
            setVisible(true);
        }
    }

    public static void main(String[] args) {
        GraphicsEnvironment env = GraphicsEnvironment.
            getLocalGraphicsEnvironment();
        GraphicsDevice[] devices = env.getScreenDevices();
        FullScreenTest test = new FullScreenTest(devices[0]);
        test.initComponents(test.getContentPane());
        test.begin();
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文