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

北慕城南 提交于 2019-12-12 15:21:37

问题


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.


回答1:


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).



来源:https://stackoverflow.com/questions/27715638/is-there-a-way-to-remove-frame-decoration-without-re-opening-it

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!