"Usually, you add internal frames to a desktop pane. The desktop pane, in turn, might be used as the content pane of a JFrame. The desktop pane is an instance of JDesktopPane."It means that you should add JInternalFrame to a JDesktopPane not to a JFrame.
但是怎么使JInternalFrame最大化后最大,最小按妞与菜单栏同一高度呢?
没经过验证。
import java.awt.*;
import com.borland.jbcl.layout.*;
import javax.swing.*;
import java.beans.*;/* Used by InternalFrameDemo.java. */
public class MyInternalFrame
extends JInternalFrame {
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...
setSize(300, 300); //Set the window's location.
setLocation(xOffset * openFrameCount, yOffset * openFrameCount);
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
} private void jbInit() throws Exception {
jButton1.setText("单击此处新增子窗口");
jButton1.addActionListener(new MyInternalFrame_jButton1_actionAdapter(this));
this.getContentPane().setLayout(xYLayout1);
this.getContentPane().add(jButton1, new XYConstraints(107, 96, -1, -1));
} XYLayout xYLayout1 = new XYLayout();
JButton jButton1 = new JButton(); void jButton1_actionPerformed(ActionEvent e) {
System.out.println("adfas");
MyInternalFrame a = new MyInternalFrame();
this.getParent().add(a);
a.setVisible(true);
try {
a.setSelected(true);
}
catch (PropertyVetoException ex) {
}
// JOptionPane.showMessageDialog(null,"dfd"); }
}class MyInternalFrame_jButton1_actionAdapter
implements java.awt.event.ActionListener {
MyInternalFrame adaptee; MyInternalFrame_jButton1_actionAdapter(MyInternalFrame adaptee) {
this.adaptee = adaptee;
} public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}