This is a simple process for Java users who want to create Multiple Document Interface Applications in Java. The application makes use of JPanels , a JFrame and a JDesktopPane.
To start with, all your child forms should be created using panels (JPanels) as the container. A frame is then created as the parent form. A desktop pane is then added to the frame to be container for the panels on the JFrame.
Below is how the application Works
1. Create your child forms on a panel
2. Create a frame and add a desktoppane to it as shown below

The black color is showing the JDesktopPane. You can set the “Anchor” and “Auto Resizing” properties of the DesktopPane so that it fits the desired size of your choice.
Add the method below to your Frame Class
public void addFrame(JPanel panel, String title) {
try {
JInternalFrame[] children = jDesktopPane1.getAllFrames();
//creating a new internal frame from the Panel passes as parameter
internalframe j = new internalframe(panel, title);
//checking to see if the child form already exist
for (JInternalFrame f : children) {
if (f.getTitle().equals(j.getTitle())) {
f.setSelected(true);
return;
}
}
//adding a new child
jDesktopPane1.add(j);
j.setVisible(true);
j.setSelected(true);
} catch (PropertyVetoException ex) {
Logger.getLogger(mainxpframe.class.getName()).log(Level.SEVERE, null, ex);
}
}
To show the child forms add the code below to the button click event
customersdetailpanel sd=new customersdetailpanel();
sd.setSize(750, 600);
addFrame(sd, "Customers Information");
the “customersdetailpanel” is one of the child forms.
Below is an interface showing showing the MDI Application

Hope this will be helpful
Hi ,
Really this was the simplest and easiest tutorial around the web ! i am working on a project and needed to build a gui using Java ! I had worked with Web interface but this seems kinda different , The information is really nice !
Comment by Manoj Kumar — March 23, 2009 @ 3:03 pm |
This tutorial was really helpful. I’m developing a MDI app for web designers and searching how it realizes. Thanks a lot from Japan.
Comment by Akihito — March 25, 2009 @ 2:30 pm |
Could you show the whole code?
I never saw JInternalFrame be created with JInternalFrame(JPane, String).
Comment by Franzisk — March 25, 2009 @ 5:28 pm |
thanks for your comment
i added a jinternal frame and added a constructor to accept a Jpanel and a string as its title
below is the class
public class internalframe extends javax.swing.JInternalFrame {
private Container contentPane = null;
/** Creates new form InternalFrame */
public internalframe() {
initComponents();
}
public internalframe( JPanel panel, String title) {
//super(parent, modal);
contentPane = this.getContentPane();
initComponents();
this.setSize(panel.getSize().width + 20, panel.getSize().height + 30);
panel.setLocation(0, 0);
contentPane.add(panel);
this.setTitle(title);
repaint();
}
/** 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.
*/
@SuppressWarnings(“unchecked”)
//
private void initComponents() {
setClosable(true);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 394, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 282, Short.MAX_VALUE)
);
pack();
}//
// Variables declaration – do not modify
// End of variables declaration
}
Comment by gilbertadjin — March 25, 2009 @ 5:42 pm |
Thanks a lot for your reply.
Comment by Franzisk — March 25, 2009 @ 5:45 pm |
That’s nice but would you mind to put source code of this implementation?
Comment by Fatih — May 19, 2010 @ 9:54 pm |
thx a lot for this tutorial
Comment by Si Paijah — June 11, 2010 @ 6:02 pm |
it really helps, thanks,
this one also helps me: http://net-effects.blogspot.com/2010/05/java-mdi-tutorial-multiple-document.html
Comment by noob — August 4, 2010 @ 6:46 am |
thanxxxxx
Comment by ahmed noue — October 3, 2010 @ 1:46 am |
i hav 1 problem in showing the child forms on the button click…
i hav used jinternalframes as child forms… i want to open another jinternalframe ( i m currently trying for..) on click of one of buttons on my form..
my mdi menubar works properly but i hav nw this problem…
plz help me.. rply me as quick as possible… thnx in advance.
Comment by preetam — October 10, 2010 @ 2:45 pm |
Thanks so much man…
It’s gonna help me in me proyect….
thanks for sharing your knowlegde..
chamoW
Quito-Ecuador
Comment by chamow — November 14, 2010 @ 8:16 pm |
[...] Creating MDI Applications in Java Using Netbeans March 200911 comments 3 [...]
Pingback by 2010 in review « Gilbert Adjin Tech Blog — January 3, 2011 @ 10:35 am |