简体   繁体   中英

How to stop mouse click when clicking on a dialog using java swt

I have a dialog and when the user clicks the ok button in the dialog, the call goes from client to the server and then starts processing. In mean time when it is in the processing stage when the user tries to click anywhere on the dialog it is getting hanged and then once the process gets complete it behaves normally. So until the process gets complete i dont want the user to click the dialog, even though if he clicks the event should not be detected and dialog should not get hanged.

I dont want use progress monitor, is there anyway to handle this?

This is code I am using after OK button Pressed

`//Server call
startServerProcess(compsTable); 
//Async to update UI 
Display.getDefault().asyncExec( new Runnable() 
{ 
    public void run() 
    { 
        label.setText("");
    }
 });`

Even though the async call is used, when user clicks anywhere on the dialog it shows hanged and says not responding. Any help for this?

Unless you are doing it asynchronously, it will behave like it does. the SWT is waiting until it gets the response back from the server, and during that time, whatever you do (eg click or do other actions) will not have any affect because it is not ready for user interaction yet.

You can run the job in a Thread, but ProgressMonitor was designed to give you a nice modal UI dialog telling you to wait. If you run a separate thread, you'll have to check if they click on the OK button twice, or some other element you left accessible.

I my opinion ergonaut's answer is correct and You should go with threads and asynchronous processing.

But if You insist to do it in one UI(!) thread then disable dialog parent composite, send, receive and process server's response. Then enable parent composite. This will block unnecessary events during processing.

parent.setEnable(false);
send(message)
process(recv());
parent.setEnable(true);

Be aware that user expects some kind of notification when something is processing. Without showing that app is busy user probably assume that application hangs and terminate it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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