开发者

Globally disable all mouse input when a JDialog is showed

开发者 https://www.devze.com 2023-02-15 06:53 出处:网络
I would like to implement what follows: when my application perform some critics opera开发者_如何学运维tions or produce some errors, i want to display an alert JDialog telling the user what is happeni

I would like to implement what follows: when my application perform some critics opera开发者_如何学运维tions or produce some errors, i want to display an alert JDialog telling the user what is happening.

Now, because some errors may put my application into an inconsistent status, until they are resolved, i would like temporarily disable mouse event dispatch to all components (including JMenu, JToolbar, .. )except the showed JDialog.

Is there anyway to do that? Or I have to manually removed all mouse listeners from all of components of my application, and re-add them later?


Make the dialog "modal" with setModal(true).


Simplest way is to call

frame.setEnabled(false);

where frame is your top-level window.

Note that the above soln may change the look of frame until its enabled again. For real control people play around with EventQueue's.

0

精彩评论

暂无评论...
验证码 换一张
取 消