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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With