有没有一种方法可以在不重新打开框架的情况下移除框架装饰? [英] Is there a way to remove frame decoration without re-opening it?

查看:54
本文介绍了有没有一种方法可以在不重新打开框架的情况下移除框架装饰?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个简单的圣经阅读器,并且希望有一个全屏选项.默认情况下,框架已最大化,但框架在那里.我有一个方法setFullScreen,它删除装饰.但是,它似乎在初始化后没有更新.有办法解决吗?

setFullScreen方法:

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

main方法的一部分

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

同时,setLabelText的行为类似;第一次设置后,就无法更改.

解决方案

仅当框架不可显示时,才可以使用方法setUndecorated().您可以做的是通过调用dispose()使框架无法显示.

您的方法setFullScreen()可能看起来像这样:

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

根据框架内容,可能需要显式处理pack()和/或setSize()以获得最佳效果.

顺便说一句,如果您希望它始终为全屏/无装饰,则可以简单地确保在使帧可显示之前调用mainFrame.setUndecorated(true).框架可以通过show()pack()setVisible(true)之类的方法显示.

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

这篇关于有没有一种方法可以在不重新打开框架的情况下移除框架装饰?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆