AWT/Swing allows to show application modal (blocking the whole application) and parent modal (blocking only the parents) dialogs. How can I achieve the same with SWT?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- SWT table: how to set/get “focused” row
In order to block the whole application, you can create the dialog
Shell
with the styleSWT.APPLICATION_MODAL
, open it, and then pump the UI events until the shell is disposed:If you want to block input only to the parent, try using the style
SWT.PRIMARY_MODAL
, though the Javadocs specify (as for the other modal styles) that this is a hint; i.e., that different SWT implementations may not exactly handle it the same way. Likewise, I don't know of an implementation that would honor theSWT.SYSTEM_MODAL
style.UPDATE: Answer to first comment
If you have two or more primary modals open at the same time, you cannot use the tricks to pump the events until the modal is closed, as they could be closed in any order. The code will run, but execution will resume after the while loop after the current dialog is closed and all other such dialogs that have been opened after it. In this case, I would register a
DisposeListener
on each dialog to get a callback when they are closed. Something like this: