在一个jfrmae 放一个button打开有个 JInternalFrame怎么做?
JIntFrame j=new JIntFrame ();
jFrame.jdp.add(j);//jdp JDesktopPane
j.setSelected(true);
}
catch(Exception e){
e.printStackTrace();
}
怎么那个窗口弹不出来!

解决方案 »

  1.   

    你首先要给这个按钮添加一个动作监听然后在 动作事件处理里面  做InternalFrame的操作,j.setVisiable(true);//显示该InternalFrame
    j.toFont();//将该InternalFrame显示在窗口最前面这样以来就可以显示出InternalFrame了你试试看吧
      

  2.   

    不可以啊我肯定在butto事件里面写的
      

  3.   

    我跟你一个完整的例子吧!import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;public class inFrame extends JFrame implements ActionListener{ //建立一个Frame窗体

    private JButton button;
    private JDesktopPane desktop; //用来存放internalFrame的容器

    public inFrame(){ //用构造函数,初始化
    //我知道你是什么问题了啊
    //主要是窗口界面重叠覆盖所造成的啊
    //我现在在contentpane上面 加了两个 容器,一个是desktop用来存放JInternalFrame的
    // 另一个是panel用来存放button的,
    //然后把他们的位置错开,这个就不会覆盖了啊
    super("InternalFrame的一个例子");
    this.setSize(800,600);
    this.setLocation(100,80);
    this.setLayout(null);

    desktop=new JDesktopPane();
    desktop.setLayout(null);
    desktop.setBounds(0,100,800,500);
    this.getContentPane().add(desktop);
    init();

    this.setVisible(true);
    }

    private void init(){ //添加按钮,并且给按钮增加 监听
    button=new JButton("打开InternalFrame");
    button.setBounds(300,25,200,40);
    button.addActionListener(this);

    JPanel panel = new JPanel();
    panel.setLayout(null);
    panel.setBounds(0,0,800,100);
    panel.add(button);
    this.getContentPane().add(panel);
     
    }

    public void actionPerformed(ActionEvent e){ //事件处理
    JInternalFrame inframe =new JInternalFrame("我是internalFrame",true,true,true,true);//定义一个inframe
    inframe.setSize(600,400);
    inframe.setLocation(50,50);

    desktop.add(inframe);//将inframe添加到desktop中
    inframe.setVisible(true);//使他显示
    }

    public static void main (String args[]){
    new inFrame();
    }
    }你自己运行一个,理解一个,就KO了啊