开发者

How to lock-down a frame in Java (GUI)

开发者 https://www.devze.com 2023-03-07 07:05 出处:网络
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

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 c开发者_运维百科an't minimize it
  • It lies on top of the taskbar and everything else (unless specified)

Basically, it's a full screen takeover.


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


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();
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消