简体   繁体   English

限制对其他JFrame的访问

[英]Restrict Access to other JFrame

How do i restrict access to other JFrame? 如何限制对其他JFrame的访问?

if I open my main frame and when click the button to display other jframe, the user should not be able to go back to the main frame. 如果打开主框架并单击该按钮以显示其他jframe,则用户应该无法返回主框架。

how do I do that? 我怎么做?

if i open my main frame and click the add button, 如果我打开主机并单击添加按钮,

When you click the button you display a modal JDialog. 单击按钮时,将显示模式JDialog。 Then until the user closes the dialog they won't be able to access the main frame. 然后,在用户关闭对话框之前,他们将无法访问主框架。

试试这个方法...

this.setEnabled(false);

Your question is not clear to me but as per my understanding I believe You want to open a dialog on button click but when you click the button a new JFrame is displayed and it becomes impossible for you to get back to the original frame. 我不清楚您的问题,但据我了解,我相信您想在单击按钮时打开一个对话框,但是当您单击按钮时,将显示一个新的JFrame,并且您将无法回到原始框架。

  1. Use a dialog /pop-up on your button click like JOptionPane. 在按钮单击上使用对话框/弹出窗口,如JOptionPane。

  2. If you want to open a JFrame on button click, making a HOME button on the newly created/opened JFrame and linking that button to main JFrame might be a good option.Closing the newly created JFrame will display the originally created JFrame anyway. 如果要在单击按钮时打开JFrame,在新创建/打开的JFrame上创建HOME按钮并将该按钮链接到主JFrame可能是个不错的选择。关闭新创建的JFrame仍会显示最初创建的JFrame。

Use a dialog ( JDialog class) instead and make it modal. 改用对话框( JDialog类)并将其设置为模态。 Here is some help on how to do this: http://download.oracle.com/javase/tutorial/uiswing/components/dialog.html 这是有关如何执行此操作的帮助: http : //download.oracle.com/javase/tutorial/uiswing/components/dialog.html

Regards, 问候,

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

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