当前位置: 技术问答>java相关
这里有一个使用JDesktopPane和JInternalFrame的例子,但是无法打开内部窗体?请给点提示,谢谢
来源: 互联网 发布时间:2015-04-24
本文导语: //我使用jcreator2.00_007+j2sdk1.3.1_02 import java.awt.*; import java.awt.event.*; import javax.swing.*; public class MDITest extends JFrame { private JButton btnAdd=new JButton("添加内部窗体"); private JDesktopPane desktopPane=new JDesktopPane(); private ...
//我使用jcreator2.00_007+j2sdk1.3.1_02
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MDITest extends JFrame
{
private JButton btnAdd=new JButton("添加内部窗体");
private JDesktopPane desktopPane=new JDesktopPane();
private int windowCount=1;
public MDITest()
{
setTitle("桌面窗格和内部窗体测试");
setSize(500,500);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent evt)
{
dispose();
System.exit(0);
}
});
Container contentPane=getContentPane();
contentPane.add(btnAdd,BorderLayout.NORTH);
contentPane.add(desktopPane,BorderLayout.CENTER);
desktopPane.setLayout(new FlowLayout());
btnAdd.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
JInternalFrame jif=new JInternalFrame(
"内部窗体"+windowCount,
true,
true,
true,
true);
jif.setPreferredSize(new Dimension(250,100));
desktopPane.add(jif);
desktopPane.revalidate();
}
});
}
public static void main(String[] args)
{
(new MDITest()).show();
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MDITest extends JFrame
{
private JButton btnAdd=new JButton("添加内部窗体");
private JDesktopPane desktopPane=new JDesktopPane();
private int windowCount=1;
public MDITest()
{
setTitle("桌面窗格和内部窗体测试");
setSize(500,500);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent evt)
{
dispose();
System.exit(0);
}
});
Container contentPane=getContentPane();
contentPane.add(btnAdd,BorderLayout.NORTH);
contentPane.add(desktopPane,BorderLayout.CENTER);
desktopPane.setLayout(new FlowLayout());
btnAdd.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
JInternalFrame jif=new JInternalFrame(
"内部窗体"+windowCount,
true,
true,
true,
true);
jif.setPreferredSize(new Dimension(250,100));
desktopPane.add(jif);
desktopPane.revalidate();
}
});
}
public static void main(String[] args)
{
(new MDITest()).show();
}
}
|
你那个internalframe必须要show,如下:
desktopPane.add(jif);
jif.show();
desktopPane.add(jif);
jif.show();