如何使用JInternalFrame

   为了创建MDI风格的GUI,可以选择JInternalFrame,并将其放入JDesktopPane中。

  ...//In the constructor of InternalFrameDemo, a JFrame subclass:
    desktop = new JDesktopPane();
    createFrame(); //Create first window
    setContentPane(desktop);
    ...
    //Make dragging a little faster but perhaps uglier.
    desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
...
protected void createFrame() {
    MyInternalFrame frame = new MyInternalFrame();
    frame.setVisible(true);
    desktop.add(frame);
    try {
        frame.setSelected(true);
    } catch (java.beans.PropertyVetoException e) {}
}

...//In the constructor of MyInternalFrame, a JInternalFrame subclass:
static int openFrameCount = 0;
static final int xOffset = 30, yOffset = 30;

public MyInternalFrame() {
    super("Document #" + (++openFrameCount),
          true, //resizable
          true, //closable
          true, //maximizable
          true);//iconifiable
    //...Create the GUI and put it in the window...
    //...Then set the window size or call pack...
    ...
    //Set the window's location.
    setLocation(xOffset*openFrameCount, yOffset*openFrameCount);
}

   1、JInternalFrame VS 普通Frame

   这两者的使用方式很相似,但InteralFrame并不是Window或Top-level容器,使用InterlFrame时,必须将其放入一个容器,比如JDesktopPane。另外,InterlFrame并不产生Window event,而是产生internal frame event。另外,InternalFrame是被设计成与JDesktopPane协同工作的,因此很多方法,如moveToFront,只有在JDesktopPane中才有效。

   2、使用InternalPane的规则

   (1)setSize 或 setBounds

   (2)setLocation

   (3)将组件添加到IntenalPane的contentPane上

   (4)InternalPane的对话框应该使用JOptionPane 的showInternalXxxDialog发病高发或 JInternalFrame实现

   (5)必须将InternalPane加入一个容器

   (6)setVisible

   (7)发出Internal Frame event,而不是window event。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值