How to use JInternalFrame in java swing

In this tutorial you will learn how to use JInternalFrame. The JInternalFrame can be used with JDesktopPane. In the real life, the JInternalFrame will be very different entities with their characteristics.

A JInternalFrame is confined to a visible area of a container it is placed in. JInternalFrame a top level swing component that has a contentpane.

JInternalFrame can be iconified — in this case the icon remains in the main application container.
JInternalFrame can be maximized — Frame consumes the main application
JInternalFrame can be closed using standard popup window controls
JInternalFrame can be layered.

Below is the code which use the JInternalFrame.

import java.awt.EventQueue;
import java.beans.PropertyVetoException;

import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;

public class JInternalFrameExample extends JFrame {

	private static final long serialVersionUID = 1L;

	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					JInternalFrameExample frame = new JInternalFrameExample();
					frame.setVisible(true);
					frame.setSize(600, 400);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	public JInternalFrameExample() throws PropertyVetoException {
		setTitle("JInternalFrame Example");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		// Create and Set up the GUI.
		JDesktopPane desktop = new JDesktopPane();

		JInternalFrame internalFrame = new JInternalFrame("Internal Frame");
		internalFrame.setVisible(true);
		internalFrame.setSelected(true);
		internalFrame.setSize(300, 300);
		desktop.add(internalFrame);

		setContentPane(desktop);
	}

}

The output of the above code will be as :

7