简体   繁体   English

即使frame为setVisible,也无法设置Undecorated(false)

[英]Can't SetUndecorated even if frame is setVisible(false)

In my application from a button See I display a jframe (undecorated, MAXIMIZED_BOTH, Visible and alwaysOnTop) then after some time when I am done working on it, I set it invisible from a button Close on that frame itself... But after that, when I again click the button to display the jframe, it says Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException: The frame is displayable. 在从一个按钮我的应用程序我展示一个JFrame(无装饰,MAXIMIZED_BOTH,可见光和alwaysOnTop),那么一些,当我完成工作就可以了时间后,我将它从框架本身上关闭按钮无形......但在那之后,再次单击该按钮以显示jframe时,它说Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException: The frame is displayable. even tough I have set the frame invisible. 甚至很难将框架设置为不可见。

Is this much information is sufficient or do you need more? 这些信息足够吗?还是您需要更多信息?

Update: My main file is FormTTS.java I also have a file named FTDirect.java , which has 3 frames: See , Blank and Main . 更新:我的主文件是FormTTS.java我也有一个名为FTDirect.java的文件,该文件具有3帧: SeeBlankMain In the Main frame I have a button See which makes the see frame visible, in the see frame after my work I make itself invisible from a button in itself and then I get returned to the main frame. 在主框架中,我有一个按钮“ 看见” ,该按钮使可见框架可见,在工作后的“看见”框架中,我使自己从按钮本身不可见,然后返回到主框架。 Now if I again click the See button I get the error 现在,如果我再次单击“ 查看”按钮,则会收到错误消息

Code: See button in Main frame in FTDirect.java 代码: 请参见 FTDirect.java中“主框架”中的按钮

See.setUndecorated(true);
See.setVisible(true);
See.setAlwaysOnTop(rootPaneCheckingEnabled);
See.setExtendedState(MAXIMIZED_BOTH);
......

Close button in See Frame in FTDirect.java 参见FTDirect.java中的“框架”中的“ 关闭”按钮

this.setVisible(false); //That's it

Minimal example program (Pseudocodes) 最小示例程序 (伪代码)

File: FormTTS.java 档案:FormTTS.java

FTdirect directform = new FTdirect();
directform.setVisible(true);
directform.setExtendedState(MAXIMIZED_BOTH);

File: FTDirect.java 文件:FTDirect.java

//Main frame
private void MainSeeButtonActionPerformed(java.awt.event.ActionEvent evt) {                                              
    See.setUndecorated(true);
    See.setVisible(true);
    See.setAlwaysOnTop(rootPaneCheckingEnabled);
    See.setExtendedState(MAXIMIZED_BOTH);
}
//See frame - Close Button
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    See.setVisible(false);
}

So concluding : I click the see button I get the See frame in there I click the close button it becomes invisible and now if I click the see button again it gives an error 因此结论 :我单击“查看”按钮,在其中看到“查看”框架,然后单击“关闭”按钮,它变为不可见,现在如果再次单击“查看”按钮,则会出现错误

Modify code for See method using Frame#isUndecorated() that Indicates whether this frame is undecorated. 使用Frame#isUndecorated()修改See方法的代码,该代码指示此框架是否未装饰。 By default, all frames are initially decorated. 默认情况下,所有框架都是最初装饰的。

if (!See.isUndecorated()) {
    See.setUndecorated(true);
}
if(!See.isVisible()){
    See.setVisible(true);
}
See.setAlwaysOnTop(rootPaneCheckingEnabled);
See.setExtendedState(MAXIMIZED_BOTH);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM