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!
# 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.
# 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
# 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?