Share on Google+Share on Google+

How to create Multiple Frames using Java Swing

In this section, you will learn how to create multiple frames using Java Swing.

Multiple Frames in Java Swing

In this section, you will learn how to create multiple frames. Java Swing provides the utility to show frame within another frame by providing the class JInternalFrame. With the use of this class, you can display a JFrame-like window within another window. It provides many of the features of a native frame, including dragging, closing, becoming an icon, resizing, title display, and support for a menu bar. Here we are going to display four internal frame on the JFrame.

Here is the code:

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;

public class MultipleFrames {
	JDesktopPane desk;
	JInternalFrame frame1, frame2, frame3, frame4;
	JFrame frame;

	public static void main(String[] args) {
		MultipleFrames d = new MultipleFrames();

	public MultipleFrames() {
		frame = new JFrame("Multiple Frames");
		desk = new JDesktopPane();
		frame1 = new JInternalFrame("Frame1", true, true, true, true);
		frame1.setBounds(20, 200, 150, 100);
		frame2 = new JInternalFrame("Frame2", true, true, true, true);
		frame2.setBounds(20, 140, 150, 100);
		frame3 = new JInternalFrame("Frame3", true, true, true, true);
		frame3.setBounds(20, 80, 150, 100);
		frame4 = new JInternalFrame("Frame4", true, true, true, true);
		frame4.setBounds(20, 20, 150, 100);
		frame.setSize(400, 400);


Posted on: October 31, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.