如何在框架可见后调用setUndecorated

如何在框架可见后调用setUndecorated

本文介绍了如何在框架可见后调用setUndecorated()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Swing应用程序中,我希望能够在装饰和未装饰之间切换,而无需重新创建整个框架。但是,在框架可见后,API不允许我调用 setUndecorated()

In my Swing application, I want the ability to switch between decorated and undecorated without recreating the entire frame. However, the API doesn't let me call setUndecorated() after the frame is made visible.

即使我调用 setVisible(false) isDisplayable()仍然返回true。 API说,使帧不可显示的唯一方法是重新创建它。但是,我不想重新设置框架只是为了关闭一些标题栏。

Even if i call setVisible(false), isDisplayable() still returns true. The API says the only way to make a frame not-displayable is to re-create it. However, I don't want to recreate the frame just to switch off some title bars.

我正在制作一个可在全屏和窗口之间切换的全屏应用程序模式;它应该能够在保持状态等的同时进行切换。

I am making a full-screenable application that can be switched between fullscreen and windowed modes; It should be able to switch while maintaining the state, etc.

如果框架可见后我该怎么做?。

How do I do this after a frame is visible?.

推荐答案

你做不到。这是我尝试实现同样目标时的经验。

You can't. That's been my experience when I tried to achieve the same.

但是,如果您的整个用户界面位于框架中的一个面板中,则可以创建一个新框架并将该面板添加到框架中。没那么多工作。

However if you have your entire UI in one panel which is in your frame, you can create a new frame and add that panel to the frame. Not so much work.

这样的事情:

// to start with
JPanel myUI = createUIPanel();
JFrame frame = new JFrame();
frame.add(myUI);

// .. and later ...

JFrame newFrame = new JFrame();
newFrame.setUndecorated();
newFrame.add(myUI);

在Swing中,面板(实际上是组件的任何实例)只能位于一个框架中时间,所以当你把它添加到一个新的框架时,它会立即停止在旧框架中。

In Swing a panel (and indeed any instance of a component) can only be in one frame at a time, so when you add it to a new frame, it immediately ceases to be in the old frame.

这篇关于如何在框架可见后调用setUndecorated()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 13:02