简体   繁体   中英

Can I permanently remove access to the taskbar when a JFrame is Maximized?

I am currently building a POS system for my Capstone project to complete my degree. I have already went WAY above and beyond the specifications for the project (will look better in my portfolio than the called for Command Window interface), and would like to add one additional feature.

When I think of a POS system, I think of an application that hides main "Windows" functionality from the user, and only allows the end user to do their job. In order to do this, I want to remove the taskbar completely while the application is running. I am currently able to make the JFrame full screen, and this hides the Windows Taskbar.

However, when the user presses ALT+TAB or the "Windows" key on the keyboard, the taskbar shows up again. This is the functionality that I would like to remove.

Here is my SSCCE:

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class TestWindow extends JFrame implements ActionListener {

    private static final long serialVersionUID = 1L;
    private JPanel contentPane;

    public void buildGUI() {
        setUndecorated(true);
        setResizable(false);
        Toolkit tk = Toolkit.getDefaultToolkit();
        int xSize = ((int) tk.getScreenSize().getWidth());
        int ySize = ((int) tk.getScreenSize().getHeight());
        setSize(xSize, ySize);
        setAlwaysOnTop(true);
        contentPane = new JPanel();
        contentPane.setLayout(new BorderLayout(0, 0));
        setContentPane(contentPane);
        setVisible(true);

        JPanel panel = new JPanel();
        contentPane.add(panel, BorderLayout.CENTER);
        JButton btn = new JButton("Exit");
        btn.addActionListener(this);
        panel.add(btn);
    }

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    new TestWindow().buildGUI();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand().equals("Exit")) {
            System.exit(0);
        }
    }
}

So would I just need to add a keyListener to check if ALT+TAB or the Windows key is being pressed? Or is there a better way to handle this?

它要求您使用SetWindowsHookEx设置向上的低级键盘挂钩(请参阅:WH_KEYBOARD_LL)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM