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
}

