The duplicate form Add button to create the Getset method on the toolbar of the form you want to replicate to get the toolbar object on the hosted form
1.
Public JToolBar getjToolBar1 () {
return jToolBar1;
}
public void SetjToolBar1 (JToolBar jToolBar1) {
This.jtoolbar1 = jToolBar1;
}
2.//Calling the Add button method in the constructor method
Public Dgeditdeclarant () {
Initcomponents ();
Pndeclarant = new Pndeclarant ();
AddButton ();
This.add (Pndeclarant, Java.awt.BorderLayout.CENTER);
}
3.//Add button
private void AddButton () {
JToolBar TB = PNDECLARANT.GETJTOOLBAR1 ();
Jbbutton btn = new Jbbutton ();
Btn.seticon (New Javax.swing.ImageIcon (GetClass () getresource ("/com/bsw/esp/client/images/35_ OK. png")); noi18n
Btn.settext ("OK");
Btn.setauthorityid ("");
Btn.setborderpainted (FALSE);
Btn.setfocusable (FALSE);
Btn.sethorizontaltextposition (0);
Btn.seticontextgap (0);
Btn.setverticaltextposition (3);
Btn.addactionlistener (new ActionListener () {
@Override
public void actionperformed (ActionEvent e) {
Selectdata = (declarant) Pndeclarant.gettablemodel (). Getcheckedrow ();
if (Selectdata = = null) {
Joptionpane.showmessagedialog (RootPane, "Please select data");
Return
} else {
IsOk = true;
Dispose ();
}
}
});
Tb.add (BTN);
}
4.//calling a hosted form
Dgeditdeclarant dg = new Dgeditdeclarant ();
Dg.setvisible (TRUE);
if (Dg.getisok ()) {
Declarant declarant = Dg.getselectdata ();
if (declarant! = null) {
Initdeclarant ();
ItemProperty it = new ItemProperty (Declarant.getcode (), Declarant.getname ());
Cbbdeclarant.setselecteditem (IT);
}
} else {
Initdeclarant ();
}
Hosting form code
public class Dgeditdeclarant extends Jdialogbase {
Private Pndeclarant pndeclarant;
Private Boolean isOk = false;
Private declarant Selectdata;
/**
* Creates new form Newjdialog
*/
Public Dgeditdeclarant () {
Initcomponents ();
Pndeclarant = new Pndeclarant ();
AddButton ();
This.add (Pndeclarant, Java.awt.BorderLayout.CENTER);
}
@Override
public void setvisible (Boolean b) {
if (b) {
super.setvisible (b);//to change body of generated Methods, choose Tools | Templates.
}
}
private void AddButton () {
JToolBar TB = pndeclarant.getjtoolbar1 ();
Jbbutton btn = new Jbbutton ();
Btn.seticon (New Javax.swing.ImageIcon (GetClass () getresource ("/com/bsw/esp/client/images/35_ OK. png")); noi18n
Btn.settext ("OK");
Btn.setauthorityid ("");
Btn.setborderpainted (FALSE);
Btn.setfocusable (FALSE);
Btn.sethorizontaltextposition (0);
Btn.seticontextgap (0);
Btn.setverticaltextposition (3);
Btn.addactionlistener (New ActionListener () {
@Override
public void actionperformed (ActionEvent e) {
Selectdata = (declarant) Pndeclarant.gettablemodel (). Getcheckedrow ();
if (selectdata = = null) {
Joptionpane.showmessagedialog (rootpane, "select data");
return;
} else {
IsOk = t Rue
Dispose ();
}
}
});
Tb.add (BTN);
}
/**
* This method was called from within the constructor to initialize the form.
* Warning:do not modify this code. The content of this method was always
* Regenerated by the Form Editor.
*/
@SuppressWarnings ("Unchecked")
<editor-fold defaultstate= "collapsed" desc= "Generated Code" >
private void Initcomponents () {
Setdefaultcloseoperation (Javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
SetBounds (0, 0, 500, 373);
}//</editor-fold>
Public Boolean Getisok () {
return isOk;
}
public void Setisok (Boolean isOk) {
This.isok = isOk;
}
Public declarant Getselectdata () {
return selectdata;
}
public void Setselectdata (declarant selectdata) {
This.selectdata = Selectdata;
}
Variables declaration-do not modify
End of variables Declaration
}
Form Loading form