calling a custom jDialog

I am using NetBeans 5.5 and created a custom jDialog. I want to be

able to call the custom jDialog from another Form. The dialog I created

allows a user to set parameters for a template. The template saves

basic employee information to a text file for populating a time card.

When the template needs to be altered, the user would call the

template, which is the custom jDialog, to reset the template.

I thought I could just instantiate the custom jDialog class I created and

use a 'go()' method to bring up the templateChooser jDialog but

nothing seems to be working. Here is some sample code:

Code from templateChooser:

publicclass templateChooserextends javax.swing.JDialog{

/** Creates new form templateChooser */

public templateChooser(){

go();

}//end template Chooser()

publicvoid go(){

initComponents();

templateAttributesEnabled(false);

jCmbxDutyDaysEnabled(false);

formLoadData_onDialogOpen();

}//end go

...

Code from tcForm.class and menu item method I use or would like to use to open that custom jDialog:

privatevoid jMenuItem_OpenTemplateMouseClicked(java.awt.event.MouseEvent evt){

//call the template dialag box

templateChooser tc =new templateChooser();

tc.go();

tc.setVisible(true);

tc.setModal(true);

}//end jMenuItem_OpenTemplateMouseClicked(java.awt.event.MouseEvent evt)

As I had previously mentioned, I want to call this jDialog class to edit

the time card template but can't get the jDialog to open. I am sure this

is quite simple but quite tired also of banging my head against desk.

Any help would be greatly appreciated!

[2542 byte] By [SaipanMan2005a] at [2007-11-26 14:34:01]
# 1
I'm only guessing since this is only part of the code, but you're calling go once in the constructor of templateChooser and once in jMenuItem_OpenTemplateMouseClicked.Usually initComponents should be done once.
Rodney_McKaya at 2007-7-8 2:30:01 > top of Java-index,Desktop,Developing for the Desktop...
# 2
I had set up the go() method to initComponents. NetBeans makes initComponents private in the declaration. Coding go public and then calling it allowed me around this; however, calling the class templateChooser() constructor does not work either.
SaipanMan2005a at 2007-7-8 2:30:01 > top of Java-index,Desktop,Developing for the Desktop...
# 3

You don't call the constructor.

When you create a new object the constructor is called.

So when you write this:

templateChooser tc = new templateChooser();

tc.go();

go is called once in the constructor and once in tc.go.

Anyway if want further help post a Short, Self Contained, Compilable and Executable, Example Program (SSCCE) that demonstrates the problem.

Rodney_McKaya at 2007-7-8 2:30:02 > top of Java-index,Desktop,Developing for the Desktop...
# 4

Ok...I understand what you are saying. I took a step back and tried it by

moving the initialization portion out of the constructor still to no avail. By

the way, I can run the jDialog portion by itself and it runs great but

calling it from the tcForm.class is where it is failing to load.

Here are sample code changes:

public class templateChooser extends javax.swing.JDialog{

/** Creates new form templateChooser */

public templateChooser() {

}//end template Chooser()

public void go(){

initComponents();

templateAttributesEnabled(false);

jCmbxDutyDaysEnabled(false);

formLoadData_onDialogOpen();

}//end go

. . .

}//end of templateChooser

public class tcForm extends javax.swing.JFrame {

public tcForm() {

initComponents();

//jf.setVisible(true);

}//end constructor

private void jMenuItem_OpenTemplateMouseClicked(java.awt.event.MouseEvent evt) {

// TODO add your handling code here:

//call the template dialag box

templateChooser tc = new templateChooser();

tc.go();

} // end jMenuItem

...

}//end class

SaipanMan2005a at 2007-7-8 2:30:02 > top of Java-index,Desktop,Developing for the Desktop...
# 5
Write a small version JFrame with only one button that opens the JDialog that has only one button.If you still see the problem, post the code.
Rodney_McKaya at 2007-7-8 2:30:02 > top of Java-index,Desktop,Developing for the Desktop...
# 6

OK... This is strange... It works now but only behind a button... and not the menuItem...

I changed the constructor to accept a frame parameter and a modal parameter.

public templateChooser(java.awt.Frame parent, boolean modal) {

super(parent, modal);

initComponents();

templateAttributesEnabled(false);

jCmbxDutyDaysEnabled(false);

formLoadData_onDialogOpen();

}//end template Chooser()

In/on the other class I used a button with mouse click event:

private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {

// TODO add your handling code here:

//javax.swing.JFrame jf = new javax.swing.JFrame();

//testJDialog td = new testJDialog(jf,true);

//td.setVisible(true);

javax.swing.JFrame jf = new javax.swing.JFrame();

templateChooser tc = new templateChooser(jf,true);

tc.setVisible(true);

}

This is the strange part, it does not work if left in the menu Item portion of the code.

private void jMenuItem_OpenTemplateMouseClicked(java.awt.event.MouseEvent evt) {

// TODO add your handling code here:

//call the template dialag box

javax.swing.JFrame nf = new javax.swing.JFrame();

templateChooser tc = new templateChooser(nf,true);

tc.setVisible(true);

}

any ideas?

SaipanMan2005a at 2007-7-8 2:30:02 > top of Java-index,Desktop,Developing for the Desktop...
# 7
I resolved the issue of why my jDialog was not opening. The action listener for the menuItem has to be set to actionPerformed instead of mouseClicked. I guess it is a NetBeans thing because I can use mouseClicked on buttons and they work fine.
SaipanMan2005a at 2007-7-8 2:30:02 > top of Java-index,Desktop,Developing for the Desktop...