Reputation: 67
I'm working on building a text editor program like NotePad. I want to make FindDialog always on top of MainFrame but user still can edit the text at JTextArea in MainFrame as NotePad.
Please help me!!!
I have used method jdialog.setModal(true). It make dialog always on top of parent but user can't edit the text at parent.
Edit: method setAlwaysOnTop() make dialog on top of all windows (include browsers,other programs..) so i can't use it
Upvotes: 0
Views: 385
Reputation: 67
I have detected that we can use super(parent) to achieve this.
class MyDialog extends JDialog {
public MyDialog(JFrame parent) {
super(parent);
}
/* Other codes */
}
Upvotes: 1
Reputation: 1340
There are various modality types (can be) supported. Use JDialog.setModalityType
method and choose the relevant modality type. For more information check out the javadoc here: https://docs.oracle.com/javase/7/docs/api/java/awt/Dialog.html#setModalityType(java.awt.Dialog.ModalityType)
BTW, calling setModal(true)
is equivalent to setModalityType(Dialog.ModalityType.MODELESS)
. In this case user can edit the parent.
So you can try either:
setModalityType(Dialog.ModalityType.DOCUMENT_MODAL)
or as you creating your JDialog pass the modality
new JDialog(parent, "Title", Dialog.ModalityType.DOCUMENT_MODAL);
There is also this useful tutorial about the modality from Oracle: https://docs.oracle.com/javase/tutorial/uiswing/misc/modality.html
Notice that there is a slight difference between Document and Application modal. Choose the appropriate one for your case.
Upvotes: 0