Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to remove frame decoration without re-opening it? [duplicate]

Tags:

java

jframe

I am making a simple bible reader, and I want to have a fullscreen option. By default, the frame is maximized, but the frame is there. I have a method, setFullScreen, that removes decoration. However, it does not seem to update after being initialized. Is there a way around this?

setFullScreen method:

public void setFullScreen() {
    mainFrame.setUndecorated(true);
}

Part of the main method

UI book = new UI();
book.setLabelText(1);
book.setFullScreen();

At the same time, setLabelText will behave similarly; once I set it the first time, I can't change it.

like image 897
CaffeineToCode Avatar asked Feb 12 '23 06:02

CaffeineToCode


1 Answers

The method setUndecorated() can only be used if the frame is not displayable. What you could do is make your frame not displayable by calling dispose().

Your method setFullScreen() could look like this:

public void setFullScreen() {
    mainFrame.dispose();
    mainFrame.setUndecorated(true);
    mainFrame.setVisible(true);
}

Depending on your frame contents, you might want to deal with pack() and / or setSize() explicitly to get best results.

By the way, if you want it to be fullscreen / undecorated always, you could simply ensure that you call mainFrame.setUndecorated(true) before you make the frame displayable. The frame is made displayable by methods such as show(), pack() and setVisible(true).

like image 90
Christian Hujer Avatar answered Feb 13 '23 21:02

Christian Hujer