Reputation: 5684
I have a problem with a custom JDialog
, that is created in its own thread by the main frame.
Sometimes the JDialog
is invisible, but its controlls are clickable (if you know where their position is). The problem does not occur on Oracle Java 1.7, but definetly on Oracle Java 1.6 (seen in 1.6.0_37 and 1.6.0_45).
I create the dialog like this:
class MyDialog extends Jdialog() {
public MyDialog(JFrame frame, boolean modal) {
super(frame, modal);
[...]
}
}
In my Mainframe:
MyDialog dialog = new MyDialog(myMainFrame,true);
dialog.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);
dialog.setVisible(true);
The expected behaviour is to block events like MouseEvents
of the mainframe and lie over it. That works perfectly on Java 1.7.
So my question is, are there any special things to keep in mind when creating JDialogs
like create it only, after the parentframe (owner) is visible or is it maybe a known bug of the used Java JRE? I already checked at the bug fix log of Oracle here without success.
Upvotes: 2
Views: 1517
Reputation: 20059
"I have a problem with a custom JDialog, that is created in its own thread by the main frame"
If thats literally true, that the problem.
You should not create instances of Swing objects, especially JComponent on any other thread than the Event Dispatch Thread. Swing is not entirely thread safe, use SwingUtilities.invokeAndWait()/invokeLater() to execute GUI related code when you're not absolutely sure you're on the EDT.
Upvotes: 2