简体   繁体   中英

Put focus on JDialog

I have class InfoDialog which extends JDialog class in Java. I show InfoDialog while I am establishing SSH connection ( 5 or 6 seconds ) with info text. How to put focus on InfoDialog that user cannot do anything else until InfoDialog runaway ?

I don't think you can lock the entire OS, but you can definetly lock your application by setting it modal. See the API of JDialog or do something like this:

 JDialog info = new JDialog();
 info.setModal(true);

I think you are looking for Modality :

Modality defines whether

The new modality model enables the developer to scope, or limit, a dialog box's modality blocking.

The following modality types are supported in Java SE 6:
Modeless type — A modeless dialog box does not block any other window while it is visible.
Document-modal type — A document-modal dialog box blocks all windows from the same document, except windows from its child hierarchy. In this context, a document is a hierarchy of windows that share a common ancestor, called the document root, which is the closest ancestor window without an owner.
Application-modal type — An application-modal dialog box blocks all windows from the same application, except windows from its child hierarchy. If several applets are launched in a browser environment, the browser is allowed to treat them either as separate applications or as a single application. This behavior is implementation-dependent.
Toolkit-modal type — A toolkit-modal dialog box blocks all windows that run in the same toolkit, except windows from its child hierarchy. If several applets are launched, all of them run with the same toolkit. Hence, a toolkit-modal dialog box shown from an applet may affect other applets and all windows of the browser instance that embeds the Java runtime environment for this toolkit.

You can define modality while creation :

JDialog dialog = new JDialog(owner, Dialog.ModalityType.DOCUMENT_MODAL);

or later :

dialog.setModalityType(type)

*There is one more level: System Level Modality , but this is not possible with just Java.

另一个选择是为此使用进度栏

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