JInternalFrame in Java Swing

JInternalFrame in Java Swing is a class that provides a lightweight way to create internal frames within a main frame or a desktop pane. JInternalFrame represents an individual internal frame within a JDesktopPane. It’s a lightweight, customizable component that can hold various types of content. We can add components such as panels, labels, buttons, etc., to a JInternalFrame.

Let’s see an example below:

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

public class JInternalFrameDemo {
	public static void main(String[] args) {
		JFrame frame = new JFrame("JInternal Frame 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);

		JPanel panel = new JPanel();
		panel.add(new JLabel("Hello, Internal Frame!"));
		internalFrame.add(panel);

		desktopPane.add(internalFrame);

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

Output:

JInternalFrame in Java Swing JDesktop internal frame in java swing
Sharing Is Caring: