user955165
user955165

Reputation: 477

Launching a frame from a dialog

I am new to Swing hopefully someone can help me out.

I have a modal JDialog d1 that contains a JXHyperlink that when I click it I should launch a JFrame f however when I do that the frame f goes behind the dialog d1 so I figured I have to set the dialog d1 to non-modal for this to work and it did!

   d1.setModal(false)

Now my problem is I have another "modal" dialog d2 that has a button where when I click it, it should launch the dialog d1 but for some reason d1 goes behind d2.

What am I doing wrong? Am I not allowed to launch a non-modal dialog from a modal dialog?

Upvotes: 2

Views: 273

Answers (2)

Colby
Colby

Reputation: 459

It is probably worth noting that modality changes cannot be made while the popup is visible. You can change the visibility (setVisible(boolean)) of the popup and then change its modality, but if it is visible any modality changes will have no effect.

Upvotes: 0

AlexR
AlexR

Reputation: 115408

Modal dialog is always shown on its parent. So, if you run any window (JFrame, non-modal JDialog) from modal dialog it is going behind.

The solution is if you want that dialog d(n) will be on dialog d(n-1) make it modal and set d(n-1) to be its parent.

So, in first case you can just change your JFrame to be JDialog an make it modal. Every time you start new instance of your dialog set the window that should be behind it as its parent. And try to avoid a lot of modal dialog boxes open at the same time. It is very annoying.

Upvotes: 2

Related Questions