📜  Java Swing-JDesktopPane

📅  最后修改于: 2020-10-01 03:17:48             🧑  作者: Mango

Java JDesktopPane

JDesktopPane类可用于创建“多文档”应用程序。一个多文档应用程序可以包含许多窗口。我们通过在主窗口中将contentPane作为JDesktopPane类或子类的实例来实现。内部窗口将JInternalFrame实例添加到JdesktopPane实例。内部窗口是JInternalFrame或其子类的实例。

领域

Modifier and Type Field Description
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 Description
JDesktopPane() Creates a new JDesktopPane.

Java JDesktopPane示例

import java.awt.BorderLayout;
import java.awt.Container;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
public class JDPaneDemo extends JFrame
{
  public JDPaneDemo() 
  {
    CustomDesktopPane desktopPane = new CustomDesktopPane();
    Container contentPane = getContentPane();
    contentPane.add(desktopPane, BorderLayout.CENTER);
    desktopPane.display(desktopPane);

    setTitle("JDesktopPane Example");
    setSize(300,350);
    setVisible(true);
  }
  public static void  main(String args[])
  {
    new JDPaneDemo();
  }
}
class CustomDesktopPane extends JDesktopPane
{
  int numFrames = 3,  x = 30, y = 30;
  public void display(CustomDesktopPane dp) 
  {
    for(int  i = 0; i < numFrames ; ++i ) 
    {
      JInternalFrame jframe = new JInternalFrame("Internal Frame " + i ,  true, true, true, true);

      jframe.setBounds(x, y, 250, 85);
     Container c1 = jframe.getContentPane( ) ;
     c1.add(new JLabel("I love my country"));
     dp.add( jframe );
     jframe.setVisible(true);
     y += 85;
    }
  }
}

输出: