简体   繁体   English

使用Java SWT单击对话框时如何停止鼠标单击

[英]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. SWT正在等待,直到它从服务器获得响应为止,在此期间,您所做的任何操作(例如,单击或执行其他操作)都不会产生任何影响,因为它尚未准备好与用户进行交互。

You can run the job in a Thread, but ProgressMonitor was designed to give you a nice modal UI dialog telling you to wait. 您可以在Thread中运行该作业,但是ProgressMonitor旨在为您提供一个漂亮的模态UI对话框,告诉您等待。 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. 我认为ergonaut的答案是正确的,您应该使用线程和异步处理。

But if You insist to do it in one UI(!) thread then disable dialog parent composite, send, receive and process server's response. 但是,如果您坚持要在一个UI(!)线程中执行此操作,然后禁用对话框父组合,请发送,接收和处理服务器的响应。 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. 如果没有显示应用程序正忙,用户可能会认为该应用程序挂起并终止。

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

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