Java:如何在显示对话框时禁用单击面板?

时间:2021-10-25 11:49:59

I want to disable clicking on the background panel or frame while showing a dialogue. And I want the dialogue to appear on top of this panel or frame constantly until it is closed.

我想在显示对话框时禁用单击背景面板或框架。我希望对话框不断显示在此面板或框架的顶部,直到它关闭。

Java:如何在显示对话框时禁用单击面板?

How can I do this?

我怎样才能做到这一点?

2 个解决方案

#1


8  

Make Dialog/JDialog modal by calling dialog.setModal(true);. This will solve both issues of clicking background panel and remaining on top of panel.

通过调用dialog.setModal(true);来创建Dialog / JDialog模式。这将解决单击背景面板和保留在面板顶部的问题。


It seems like this method is obsolete so better you should use dialog.setModalityType(Dialog.ModalityType type)

看起来这个方法已经过时了,所以你应该使用dialog.setModalityType(Dialog.ModalityType type)

#2


4  

You can use JOptionPane for the message dialog.

您可以使用JOptionPane作为消息对话框。

#1


8  

Make Dialog/JDialog modal by calling dialog.setModal(true);. This will solve both issues of clicking background panel and remaining on top of panel.

通过调用dialog.setModal(true);来创建Dialog / JDialog模式。这将解决单击背景面板和保留在面板顶部的问题。


It seems like this method is obsolete so better you should use dialog.setModalityType(Dialog.ModalityType type)

看起来这个方法已经过时了,所以你应该使用dialog.setModalityType(Dialog.ModalityType type)

#2


4  

You can use JOptionPane for the message dialog.

您可以使用JOptionPane作为消息对话框。