Create a Desktop Pane Container in Java

In this section, you will learn how to create a desktop pane container in Java.

Create a Desktop Pane Container in Java

In this section, you will learn how to create a desktop pane container in Java.

Create a Desktop Pane Container in Java

Create a Desktop Pane Container in Java

     

In this section, you will learn how to create a desktop pane container in Java. The desktop pane container is a container, which has the internal frame. This internal frame has the same feature as like a frame. The desktop pane is like a MDI (Multiple Document Interface) frame and all internal frames are like the child frame for the main frame. All internal frames open under the desktop pane. Following figure shows the JDesktopPane component of Java Swing:

Swing JDesktopPane component with a child frame

This program shows the internal frame inside the MDI frame. The internal frame has two command buttons: Ok and Cancel. This frame has the minimize, maximize and close buttons that provides the minimize (iconify), maximize and the close operations. Buttons on the internal frame have the tool tip text. Following methods and APIs have been used in the given program for getting the desktop pane container:

JInternalFrame(String iframe_title, Boolean resizable, Boolean closable, Boolean maximizable, Boolean minimizable ):

JInternalFrame():
This is the constructor of JInternalFrame class. It extends from the JComponent. This constructor has been used to create a new internal frame. This constructor takes some argument as follow:

  • First is the title of the internal frame which has to be shown in the desktop pane.
  • Second is the boolean value either true or false which determines the frame should be resizable or not.
  • Third is also a boolean value true or false which determines the frame should be closable or not.
  • Fourth is also a boolean value true or false which determines the frame should be maximize or not.
  • And last is also a boolean value which determines for the iconifying.

JDesktopPane:
This is the class which creates a desktop pane like MDI (Multiple Document Interface).

Here is the code of program:

import javax.swing.*;

public class DesktopContainer{
  JFrame frame;
  JPanel panel;
  JInternalFrame iframe;
  JButton button1, button2;
  JDesktopPane desk;
  public static void main(String[] args) {
  DesktopContainer d = new DesktopContainer();
  }
  public DesktopContainer(){
  frame = new JFrame("Creating a JDesktopPane Container");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  iframe = new JInternalFrame("Internal frame", true,true,true,true);
  iframe.setToolTipText("This is internal frame");
  panel = new JPanel();
  button1 = new JButton("Ok");
  button1.setToolTipText("This is Ok button of internal frame");
  panel.add(button1);
  button2 = new JButton("Cancel");
  button2.setToolTipText("This is cancel button of internal frame");
  panel.add(button2);
  iframe.add(panel);
  iframe.setSize(250,300);
  iframe.setVisible(true);
  desk = new JDesktopPane();
  desk.add(iframe);
  frame.add(desk);
  frame.setSize(400,400);
  frame.setVisible(true);
  }
}

Download this example