如何删除 "fullscreenmode" 中的这个栏?

How can I remove this Bar in "fullscreenmode"?

我的问题是屏幕顶部有一个小栏,我想将其删除(我希望图片全屏显示)。我不确定这个栏是从哪个来源引起的。

picture

到目前为止,这是我的代码:

    lpane = new JLayeredPane();
    lpane.setBackground(Color.BLACK);
    panelBlue = new JPanel();
    panelGreen = new JPanel();
    frame.add(lpane);
    frame.setExtendedState(Frame.MAXIMIZED_BOTH);
    frame.setUndecorated(true);
    lpane.setBounds(0, 0, 1920, 1080);
    BufferedImage background = null;
    BufferedImage title = null;
    try{
        background = javax.imageio.ImageIO.read(getClass().getResource("resources/background.jpg"));
    }catch(IOException ex){
        sendErrorMessage("Picture couldn't be loaded"); //custom Errormessage Method
    }
    JLabel picLabel = new JLabel(new ImageIcon(background));
    ImageIcon buttonbackground = new ImageIcon(flames);
    panelBlue.add(picLabel);
    panelBlue.setBounds(0, 0, 1920, 1080);
    panelBlue.setOpaque(true);

    frame.pack();
    frame.setVisible(true);

我不确定是 JLabel 的原因还是与未装饰的框架有关。

是什么原因造成的?我怎样才能删除该栏? 提前致谢

不要使用 setBounds。这是完全错误的。正确的方法是使用适当的LayoutManager。此外,如果你使用pack(),之前使用setBounds是没有用的。

要将框架置于全屏模式,您可以使用以下任一方法:

  • frame.setExtendedState(frame.getExtendedState() & JFrame.MAXIMIZED_BOTH);
  • GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(frame);

请看这个例子来说明这一点:

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.net.MalformedURLException;
import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UnsupportedLookAndFeelException;

public class TestFullScreen {

    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException,
            UnsupportedLookAndFeelException {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    new TestFullScreen().initUI();
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    public static class ImagePanel extends JPanel {
        private ImageIcon imageIcon;

        public ImagePanel(ImageIcon imageIcon) {
            super();
            this.imageIcon = imageIcon;
        };

        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            g.drawImage(imageIcon.getImage(), 0, 0, getWidth(), getHeight(), this);
        }

        @Override
        public Dimension getPreferredSize() {
            return new Dimension(imageIcon.getIconWidth(), imageIcon.getIconHeight());
        }

    }

    protected void initUI() throws MalformedURLException {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLayout(new BorderLayout());
        frame.add(new ImagePanel(new ImageIcon(new URL("http://blog.timesunion.com/opinion/files/2011/10/brickwall.jpg"))));
        frame.setUndecorated(true);
        frame.pack();
        frame.setExtendedState(frame.getExtendedState() & JFrame.MAXIMIZED_BOTH);
        // GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(frame);
        frame.setVisible(true);
    }

}