Disable JFrame when a new JFrame is opened

烈酒焚心 提交于 2019-12-04 03:39:48

问题


I am trying to disable the "main" JFrame when the new frame pops up. I want it so you can not click or drag anything on that frame. I tried making the new frame a JDialog, but that did not disable the other frame. I also looked at the other post about this, which suggested to make it a JDialog but it still does not work. I really need help doing this please. thanks. This is the codeIi am using to make the JDialog, is their any problems with it?

editDialog=new JDialog(IntroScreen.frame);

IntroScreen.frame represents the "main" frame.


回答1:


You have set for JDialog#setModal or JDialog#ModalityTypes, maybe with Dialog.ModalityType APPLICATION_MODAL




回答2:


If you want to use multiple JFrames you could use the method setEnabled() when you open the other JFrame.

frame.setEnabled(false);

Otherwise you should go with JDialog and its method setModal().



来源:https://stackoverflow.com/questions/9627078/disable-jframe-when-a-new-jframe-is-opened

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