سؤال

I want to implement full screen exclusive mode in my already made program, my main class is freeTTS.java which is:

package freetts;

public class FreeTTS {

public static void main(String[] args) {


   new FormTTS().setVisible(true);


    }
}

The other code of the whole program is in FormTTS.java which is a subclass of JFrame.

I tried to put the code to make it full screen in here but it gave all sorts of different errors, Do I have to put the code in FreeTTS or FormTTS?

Here is my file struct: (Note: FormTTS is another java file) enter image description here

See i want to remove the pinkish whole border: enter image description here

هل كانت مفيدة؟

المحلول

From your last question, The answer may have been incompatible with the netbeans GUI builder formatting and with your program design, So here is an example that may be more compatible. Try it out and see what happens.

import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.GridBagLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class FormTTS extends JFrame {
    private boolean isFullScreen = false;
    private JButton button;

    public FormTTS() {
        initComponents();
        initFullScreen();
    }

    private void initComponents() {
        setLayout(new GridBagLayout());
        button = new JButton(
                "I'm a smallbutton in a Huge Frame, what the heck?!");
        add(button);

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
    }

    private void initFullScreen() {
        GraphicsEnvironment env = GraphicsEnvironment
                .getLocalGraphicsEnvironment();
        GraphicsDevice device = env.getDefaultScreenDevice();
        isFullScreen = device.isFullScreenSupported();
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setUndecorated(isFullScreen);
        setResizable(!isFullScreen);
        if (isFullScreen) {
            // Full-screen mode
            device.setFullScreenWindow(this);
            validate();
        } else {
            // Windowed mode
            this.pack();
            this.setExtendedState(MAXIMIZED_BOTH);
            this.setVisible(true);
        }
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new FormTTS().setVisible(true);
            }
        });
    }
}

نصائح أخرى

You should just be able to do the following, although I recommend having a read of the official guide on fullscreen exclusive mode.

FormTTS ftts = new FormTTS();

GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
gd.setFullScreenWindow(ftts);

ftts.setUndecorated(true);
ftts.setVisible(true);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top