Many of today’s applications provide a facility wherein the users can open multiple documents without having to close current document. They can then switch between the documents and update them. For this purpose, applications use the multiple-document interface to manage these multiple open documents being processed in parallel (This is a main window, often called parent window, which contains several other windows, which also called child window.) JDesktopPane and JlnternalFrame classes of the Swing package help to create these multiple-document interfaces.
Constructors and methods in the JDesktopPane class.
Constructors and Methods | Description |
JDesktopPane() | Constructs a new JDesktopPane object. |
JlnternalFrame() | Constructs a new JlnternalFrame object, which is a non-resizable, non-closable, non-maximizable, non iconifiable internal frame. |
JlnternalFrame(String title) | Constructs a new JlnternalFrame object with the specified title, which is non-resizable, non-maximizable, non- closable, non-iconifiable internal frame. |
JInternalFrame(String title, boolean resizable) | Constructs a new JlnternalFrame object with the specified title and if resizable is set true, then it is resizable internal frame, which is non-maximizable, non-closable and non iconifiable. |
JInternalFrame(String title, boolean resizeable, boolean closable) | Constructs a new JlnternalFrame object with the specified title and if resizable and closable are set true, then this internal frame is both resizable and closable but non maximizable and non-iconifiable. |
JInternalFrame(String title, boolean resizable, boolean dosable, boolean maximizable) | Constructs a new JlnternalFrame object with the specified title and if resizable closable and maximizable are set true, then this internal frame is resizable, closable and maximizable but non-iconifiable. |
JInternalFrame(String title, boolean resizable, boolean closable, boolean maximizable, boolean iconifiable) | Constructs a new JlnternalFrame object with the specified title and if resizable, closable, maximizable and iconifiable are set true, then this internal frame is resizable, closable, maximizable and iconifiable. |
Container getContentPane() | Returns the content pane of this internal frame. |
JMenuBar getJMenuBar() | Returns the current jMenuBar object for this internal frame or returns null if no menu bar is set. |
String get Title() | Returns the title of this internal frame. |
protected void paintComponent(Graphics g) | Paints the current component in internal frame. |
Void remove(Component component) | Removes the specified component from this internal frame. |
void reshape(int x, int y, int width, int height) | Moves and resizes the internal frame to the size specified by the parameters. |
void show() | Displays the internal frame as well as brings it to front. |
Program demonstrates the use of jDesktopPane.
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class JavaExampleInternalFrameInAppletSwing extends JApplet implements ActionListener
{
JDesktopPane Dsktppn = new JDesktopPane();
static int FrmNmbr = 1;
public void init()
{
JPanel Pnl = new JPanel();
Container Cntnr = getContentPane();
JButton BtnFrme = new JButton("Click For Internal Frame");
Pnl.add(BtnFrme);
Cntnr.add(Pnl,BorderLayout.SOUTH);
Cntnr.add(Dsktppn,BorderLayout.CENTER);
BtnFrme.addActionListener(this);
}
public void actionPerformed(ActionEvent Evnt)
{
JInternalFrame Intrnlfrm = new JInternalFrame();
Container Cntnr = Intrnlfrm.getContentPane();
Intrnlfrm.setLocation(5,5);
Intrnlfrm.setTitle("Internal Frame"+FrmNmbr);
FrmNmbr++;
Intrnlfrm.setClosable(true);
Intrnlfrm.setResizable(true);
Intrnlfrm.setMaximizable(true);
Intrnlfrm.setIconifiable(true);
Intrnlfrm.setVisible(true);
Cntnr.setLayout(new FlowLayout());
Cntnr.add(new JTextArea(5,10),"Center");
Intrnlfrm.pack();
Dsktppn.add(Intrnlfrm,2);
}
}
/*<APPLET CODE =JavaExampleInternalFrameInAppletSwing.class WIDTH=370 HEIGHT=300></APPLET>*/