Java JDesktopPane
The JDesktopPane class, can be used to create "multi-document" applications. A multi-
document application can have many windows included in it. We do it by making the
contentPane in the main window as an instance of the JDesktopPane class or a subclass.
Internal windows add instances of JInternalFrame to the JdesktopPane instance. The
internal windows are the instances of JInternalFrame or its subclasses.
Fields
Modifier and Field Description
Type
static int LIVE_DRAG_MODE It indicates that the entire contents of the item being
dragged should appear inside the desktop pane.
static int OUTLINE_DRAG_MODE It indicates that an outline only of the item being
dragged should appear inside the desktop pane.
Constructor
Constructor Description
JDesktopPane() Creates a new JDesktopPane.
Java JDesktopPane Example
1. import java.awt.BorderLayout;
2. import java.awt.Container;
3. import javax.swing.JDesktopPane;
4. import javax.swing.JFrame;
5. import javax.swing.JInternalFrame;
6. import javax.swing.JLabel;
7. public class JDPaneDemo extends JFrame
8. {
9. public JDPaneDemo()
10. {
11. CustomDesktopPane desktopPane = new CustomDesktopPane();
12. Container contentPane = getContentPane();
13. contentPane.add(desktopPane, BorderLayout.CENTER);
14. desktopPane.display(desktopPane);
15.
16. setTitle("JDesktopPane Example");
17. setSize(300,350);
18. setVisible(true);
19. }
20. public static void main(String args[])
21. {
22. new JDPaneDemo();
23. }
24. }
25. class CustomDesktopPane extends JDesktopPane
26. {
27. int numFrames = 3, x = 30, y = 30;
28. public void display(CustomDesktopPane dp)
29. {
30. for(int i = 0; i < numFrames ; ++i )
31. {
32. JInternalFrame jframe = new JInternalFrame("Internal Frame " + i , true, true, true, t
rue);
33.
34. jframe.setBounds(x, y, 250, 85);
35. Container c1 = jframe.getContentPane( ) ;
36. c1.add(new JLabel("I love my country"));
37. dp.add( jframe );
38. jframe.setVisible(true);
39. y += 85;
40. }
41. }
42. }
Output: