>>>Can I use the 'this'-pointer to the not-yet constructed JFrame?
>>>
[quoted text clipped - 9 lines]
> I am afraid that is not so. The output of this tiny program indicates that
> the JDialog is constructed before the constructor of JFrame is called:
No it doesn't.
> class MyDialog extends javax.swing.JDialog
> {
[quoted text clipped - 11 lines]
> //MyDialog.constructor
> //MyFrame.constructor
As I say, the initialiser for jdialog runs *immediately* after super()
returns. Your code prints "MyFrame.constructor" after super() returns,
and after the initialisers have run.
class MyDialog extends javax.swing.JDialog {
MyDialog(javax.swing.JFrame frame) {
System.out.println(
"MyDialog.constructor, frame.title: "+frame.getTitle()
);
}
}
class MyFrame extends javax.swing.JFrame {
private MyDialog mydialog = new MyDialog(this);
MyFrame() {
super(print("--- title ---"));
System.out.println("MyFrame.constructor, after super");
}
private static String print(String msg) {
System.out.println("Print: "+msg);
return msg;
}
public static void main(String[] args){
new MyFrame();
}
}
$ java MyFrame
Print: --- title ---
MyDialog.constructor, frame.title: --- title ---
MyFrame.constructor, after super
The title property is set in the JFrame constructor. The MyDialog
constructor reads that property, so must have printed the message after
the JFrame constructor ran.
Tom Hawtin

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/
Martijn Mulder - 13 Feb 2006 21:55 GMT
>>>>Can I use the 'this'-pointer to the not-yet constructed JFrame?
>>>>
[quoted text clipped - 65 lines]
> constructor reads that property, so must have printed the message after
> the JFrame constructor ran.
Very convincing example. Thanks a lot!