2014-04-29 21 views
0

我完成了在我的JFrame里面添加JInternalFrame并且添加了方式是点击JMenuItem图标并且这样做很好,但是当添加了框架时删除了旧组件并出现白色。我所试图做的是设置固定JInternalFrame位置用出效果的其他成分为什么JInternalFrame删除所有其他组件

对JInternalFrame

package animeaidvlcj; 

import javax.swing.JInternalFrame; 


/* Used by InternalFrameDemo.java. */ 
public class MyInternalFrame extends JInternalFrame { 
    static int openFrameCount = 0; 
    static final int xOffset = 0, yOffset = 25; 

    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... 
     setSize(300,300); 

     //Set the window's location. 
     setLocation(xOffset*openFrameCount, yOffset*openFrameCount); 
    } 
} 

动作代码的代码的其他组件

Action newAction = new AbstractAction("New", newIcon) { 
     @Override 
     public void actionPerformed(ActionEvent e) { 
      desktop = new JDesktopPane(); 
      createFrame(); 
      setContentPane(desktop); 
      desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); 
     } 
    }; 

创建方法

protected void createFrame() { 
    MyInternalFrame frame = new MyInternalFrame(); 
    frame.setVisible(true); //necessary as of 1.3 
    desktop.add(frame); 
    try { 
     frame.setSelected(true); 
    } catch (java.beans.PropertyVetoException e) {} 
} 
+0

为了尽快提供更好的帮助,请发布[MCVE](http://stackoverflow.com/help/mcve)(最小完整和可验证示例)。 –

回答

2

“为什么是JInternalFrame删除所有其他部件的”

先好好看看这段代码在你的Action

desktop = new JDesktopPane(); 
createFrame(); 
setContentPane(desktop); <== this line in particular 

您正在设置帧的内容窗格(假设setContenPane()被调用类框架)与desktop,这将删除以前的内容窗格,其中包含所有组件。所以唯一会出现的是desktop以及新的JInternalFrame

除非你正在创建一个Multiple Document Interface (MDI),哪个桌面窗格和内部框架主要用于,我建议你只使用JDialog而忘记DesktopPane。你可以看到How to use Dialogs。这与创建JFrame几乎相同,只是您可以选择modality

+0

我想为vlcj使用其他框架,所以其他选项是坏主意,但我可以将setContentPane(桌面)替换为其他像jpanel – loverBoy

+0

这两个框架需要同时访问吗?就像新窗口打开时一样,是否希望能够访问主框架? –

+0

是绝对的,但我不确定,因为我认为vlcj可以在其他框架中运行,而我正在使用主框架 – loverBoy

相关问题