Display dialog after frame opens, not before

public main ()

{

initComponents ();

p_intro intro =new p_intro ();

intro.showInDialog (this));

}

I've got a modal dialog that I want to display after the frame opens. I tried using the code above, but I the dialog displays first and once the dialog has been closed, then the frame displays. Why is it doing that?

The frame was created with the NetBeans GUI so there is some generated code, but intro.showInDialog(); is what I want to display after the frame is loaded. It's called after initComponents() is so why is it loading first?

import java.awt.BorderLayout;

import java.awt.Dimension;

import java.awt.Toolkit;

import javax.swing.JDialog;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.Timer;

/*

* main.java

*

* Created on June 1, 2007, 3:04 AM

*/

/**

*

* @author tristan

*/

publicclass mainextends javax.swing.JFrame

{

/**

* Creates new form main

*/

public main ()

{

initComponents ();

p_intro intro =new p_intro ();

intro.showInDialog (this);

}

/** This method is called from within the constructor to

* initialize the form.

* WARNING: Do NOT modify this code. The content of this method is

* always regenerated by the Form Editor.

*/

// <editor-fold defaultstate="collapsed" desc=" Generated Code ">

privatevoid initComponents()

{

jMenuBar1 =new javax.swing.JMenuBar();

jMenu1 =new javax.swing.JMenu();

jMenu2 =new javax.swing.JMenu();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

setTitle("Hub Evaluations");

Toolkit tk = Toolkit.getDefaultToolkit();

Dimension screenSize = tk.getScreenSize();

int screenHeight = screenSize.height;

int screenWidth = screenSize.width;

setSize(screenWidth / 2, screenHeight / 2);

setLocation(screenWidth / 4, screenHeight / 4);

setResizable(false);

jMenu1.setText("File");

jMenuBar1.add(jMenu1);

jMenu2.setText("Help");

jMenuBar1.add(jMenu2);

setJMenuBar(jMenuBar1);

javax.swing.GroupLayout layout =new javax.swing.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGap(0, 657, Short.MAX_VALUE)

);

layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGap(0, 475, Short.MAX_VALUE)

);

pack();

}// </editor-fold>

/**

* @param args the command line arguments

*/

publicstaticvoid main (String args[])

{

java.awt.EventQueue.invokeLater (new Runnable ()

{

publicvoid run ()

{

new main ().setVisible (true);

}

});

}

// Variables declaration - do not modify

private javax.swing.JMenu jMenu1;

private javax.swing.JMenu jMenu2;

private javax.swing.JMenuBar jMenuBar1;

// End of variables declaration

}

[5139 byte] By [tristanlee85a] at [2007-11-27 6:40:21]
# 1
You're naming a class "main"? That seems confusing at best and dangerous at worst.
petes1234a at 2007-7-12 18:09:34 > top of Java-index,Java Essentials,Java Programming...
# 2

while(dialog is still open){

// no code here just loop to prevent other window to show

}

don't know if this is proper but I usually do this to prevent other frame to load.... ^_^

Yannixa at 2007-7-12 18:09:34 > top of Java-index,Java Essentials,Java Programming...
# 3
How is that dangerous? I didn't follow the rule of class names being uppercase and method lower case, but I've been refactoring my code to fix that.
tristanlee85a at 2007-7-12 18:09:34 > top of Java-index,Java Essentials,Java Programming...
# 4

> > while(dialog is still open){

> // no code here just loop to prevent other window

> to show

>

>

>

> don't know if this is proper but I usually do this to

> prevent other frame to load.... ^_^

I want to display the frame first and then the dialog. Your method would simply keep the frame hidden until the dialog is closed which is what my application currently does.

tristanlee85a at 2007-7-12 18:09:34 > top of Java-index,Java Essentials,Java Programming...
# 5

If you add to the end of your initComponents the setVisible method, and remove it from your constructor call in the main method, you will at least see the JFrame behind your dialog. Something like this:

private void initComponents()

{

jMenuBar1 = new javax.swing.JMenuBar();

jMenu1 = new javax.swing.JMenu();

jMenu2 = new javax.swing.JMenu();

............

............

............

............

pack();

setVisible(true); // put this here

}// </editor-fold>

public static void main(String args[])

{

java.awt.EventQueue.invokeLater(new Runnable()

{

public void run()

{

//new main().setVisible(true); // get it out of here

new main();

}

});

}

Problem is, this would require you to change the immaculte netbeans generated code.

petes1234a at 2007-7-12 18:09:34 > top of Java-index,Java Essentials,Java Programming...
# 6

> How is that dangerous? I didn't follow the rule of

> class names being uppercase and method lower case,

> but I've been refactoring my code to fix that.

it only duplicates the name of the most important method of every java program, the method that the JVM looks for to starts things off. This just doesn't smell right to me.

petes1234a at 2007-7-12 18:09:34 > top of Java-index,Java Essentials,Java Programming...
# 7
Ehh, a text editor gets passed that code. Thanks!
tristanlee85a at 2007-7-12 18:09:34 > top of Java-index,Java Essentials,Java Programming...