Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Example Java Swing Create a Desktop Pane Container in Java

Related Tutorials


 
 

Share on Google+Share on Google+

Create a Desktop Pane Container in Java

Advertisement
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. 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

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  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.

Posted on: April 14, 2007

Related Tutorials

Discuss: Create a Desktop Pane Container in Java   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com