Show JDialog ("Wait") on JFrame

I have a JFrame and this JFrame has a JButton .

I want in JButton first show JDialog (display "Please wait" ) and execute another code, and then close JDialog .

But when JDialog , execution of other JButton code is stopped.

+4
source share
4 answers

Start another processing on Thread (for example, in SwingWorker ) and at the beginning of it, call modalDialog.setVisible(true) , At the end of the call to setVisible(false) .

+4
source

I would suggest creating a simple JDialog and then deleting it after running your code. You can create your JDialog with the following code:

 JDialog dialog = new JDialog(); JLabel label = new JLabel("Please wait..."); dialog.setLocationRelativeTo(null); dialog.setTitle("Please Wait..."); dialog.add(label); dialog.pack(); 

And implement it as follows:

 dialog.setVisible(true); // show the dialog on the screen // Do something here dialog.setVisible(false); // set visibility to false when the code has run 
+4
source

Perhaps jdialog is in modal mode, try changing the modal property of jdialog: yordialog.setModal(false) .

+2
source

He stopped because you are using the "MAIN-Thread", which is used to execute code and shows JDialog.

To solve this problem you should learn something like SwingWorker

+1
source

Source: https://habr.com/ru/post/1389872/


All Articles