如何使用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。

### 回答1: 可能是因为以下原因导致jinternalframe窗口不显示: 1. 没有将jinternalframe添加到JDesktopPane中。 2. jinternalframe的setVisible属性设置为false。 3. jinternalframe的大小设置为或者太小。 4. jinternalframe的位置设置在屏幕外。 5. jinternalframe的内容为空或者没有添加组件。 6. jinternalframe的背景色与父容器相同,导致看不到。 7. jinternalframe的层级设置不正确,被其他组件遮挡。 需要检查以上问题,才能解决jinternalframe窗口不显示的问题。 ### 回答2: jInternalFrame是Java Swing框架中的一个内部窗口,用于在应用程序的主窗口中创建一个独立的子界面。如果jInternalFrame窗口没有显示出来,可能是由于以下原因: 1. 必须将jInternalFrame对象添加到JDesktopPane窗口中。JDesktopPane是用于管理内部窗口的容器。要显示jInternalFrame,请确保将其添加到JDesktopPane中。 2. 在添加jInternalFrame到JDesktopPane之前,必须先将其设置为可见。只有当jInternalFrame可见时,才能被正确地添加到JDesktopPane中。 3. 可能是由于jInternalFrame设置了错误的大小或位置导致无法显示。请检查其大小和位置属性,并确保它们与容器对齐。 4. 可能是由于jInternalFrame的默认的关闭操作设置有误。如果默认操作设置为HIDE_ON_CLOSE,那么当用户关闭jInternalFrame时,它将被隐藏而不是销毁。要完全销毁jInternalFrame,请将默认关闭操作设置为DISPOSE_ON_CLOSE。 5. 可能是由于jInternalFrame被添加到了错误的父容器中。jInternalFrame只能被添加到JDesktopPane中,如果被添加到其他容器中将无法正常显示。 综上所述,jInternalFrame窗口不显示可能是由于容器的设置问题,可见性属性设置问题,大小、位置属性设置问题或默认关闭操作设置问题。要解决这些问题,请仔细检查代码并进行调试,在错误得到修复之前,请勿放弃,像解决其他问题一样,持之以恒! ### 回答3: JInternalFrame是Java Swing中的内部窗口,它可以在应用程序的主窗口中创建子窗口来显示一些弹出式的交互窗口内容。但是,在一些情况下,我们可能会发现JInternalFrame窗口并没有显示出来。 首先,我们需要确定JInternalFrame对象已经正确创建并添加到JDesktopPane中。如果这一步骤都没有问题,那么我们需要检查一些可能导致JInternalFrame不显示的原因。 首先,我们需要检查JInternalFrame的可见性。在默认情况下,JInternalFrame是不可见的。所以,我们需要通过设置JInternalFrame的setVisible(true)方法来确保它是可见的。 其次,我们需要设置JInternalFrame的大小和位置。在默认情况下,JInternalFrame的大小会根据内容自动调整大小,但它并不一定满足我们的要求。因此,我们需要调用setBounds(x, y, width, height)方法来设置JInternalFrame的大小和位置。 还有一个处理JInternalFrame不显示的问题的方法是检查是否已经将JInternalFrame添加到正确的容器中。我们需要将JInternalFrame添加到JDesktopPane中以便显示,在这种情况下,我们需要确保JInternalFrame已经被正确添加到JDesktopPane中。 最后,我们还要检查我们的代码是否有错误。当我们使用函数或者方法时,我们需要确保这些函数和方法调用没有错误或异常。这是最基本的调试流程。通常来说,错误和异常总是能暴露问题的原因。 总之,当我们使用JInternalFrame时,我们需要确保它被设置为可见,大小和位置也被设置为正确,以及已经添加到正确的容器中。同时,我们还要注意不断查找代码中可能导致这一问题的错误或异常。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值