JDesktopPane in Java Swing

JDesktopPane in Java Swing is a container that allows us to create an MDI (Multiple Document Interface) application in Java. An MDI application is an application that can have multiple child windows within the main window. Each child window represents a different document or task, and the user can switch between them.

JDesktopPane is a container used to hold multiple internal frames. It acts as a workspace for internal frames, allowing them to be managed and displayed within its bounds. It provides a platform for arranging internal frames, enabling overlapping, minimizing, maximizing, and tiling of these frames.

Following is aa basic example of how we can create and use a JDesktopPane:

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

public class JDesktopPaneDemo {
	public static void main(String[] args) {
		JFrame frame = new JFrame("Desktop Demo");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		JDesktopPane desktopPane = new JDesktopPane();
		frame.add(desktopPane);

		JInternalFrame internalFrame = new JInternalFrame("Internal Frame", true, true, true, true);
		internalFrame.setSize(200, 200);
		internalFrame.setVisible(true);

		desktopPane.add(internalFrame);

		frame.setSize(400, 400);
		frame.setVisible(true);
	}
}

Output:

JDesktopPane in Java Swing JDesktop Pane in java swing

Reference: https://docs.oracle.com/javase/tutorial/uiswing/components/internalframe.html