简体   繁体   中英

I can't see my window with FullscreenWindow

Everything is black.

btnFullScreen.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent event) {
                GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
                GraphicsDevice gd = ge.getDefaultScreenDevice();
                if (gd.isFullScreenSupported()) {
                    gd.setFullScreenWindow(frame);
                }
            }
        });
 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
                GraphicsDevice gd = ge.getDefaultScreenDevice();
                if (gd.isFullScreenSupported()) {
                    gd.setFullScreenWindow(frame);
                }

The gd.setFullScreenWindow(frame); function requires that frame is not visible prior to this function invocation:

From the documentation :

When entering full-screen mode, if the window to be used as a full-screen window is not visible , this method will make it visible. It will remain visible when returning to windowed mode.

When entering full-screen mode, all the translucency effects are reset for the window. Its shape is set to null, the opacity value is set to 1.0f, and the background color alpha is set to 255 (completely opaque) . These values are not restored when returning to windowed mode.

It is unspecified and platform-dependent how decorated windows operate in full-screen mode. For this reason, it is recommended to turn off the decorations in a Frame or Dialog object by using the setUndecorated method.

What is wrong with : jFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);

Edit: a demo to support my claim, And this is what we call SSCCE I have a button too, the frame is minimized to the button's size. Click on the button to see in action of setExtendedState(JFrame.MAXIMIZED_BOTH) function.

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

class MyWindow extends JFrame
{
    int width=GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().width;
    int height=GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().height;
    public MyWindow ()
    {

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JButton button = new JButton("Click Me");
        button.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
               setExtendedState(JFrame.MAXIMIZED_BOTH);
            }
        });

        add(button);
        pack();

    }

    public static void main(String[] args)
    {
        new MyWindow().setVisible(true);

    }
}

Edit: From your below comment:

Yes,but i want fullscreen,because my application already obtains to be maximized.

You are probably after the function: jFrame.setUndecorated(true); , which will remove the title bar and all to make the frame contain the full screen.

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