我在主框架中创建了一个内部框架,我想从旧框架中打开另一个内部框架。
我不知道该怎么做。有什么建议吗?
我尝试了许多不同的方法来打开另一个内部框架:
我用Google搜索并搜索了Stack Overflow但找不到任何答案。
答案 0 :(得分:5)
好吧,您可以从Java教程How to Use Internal Frames
开始但可能的过程可能类似于
JInternalFrame newFrame = JInternalFrame();
newFrame.setBounds(10, 10, 100, 100);
newFrame.setVisible(true);
getParent().add(newFame); // assuming our current class is a JInternalFrame on a JDeskTop
答案 1 :(得分:2)
你可以这样做:
public class InternalFrameDemo extends JFrame {
static int openFrameCount = 0;
static final int xOffset = 30, yOffset = 30;
JDesktopPane desktop;
public InternalFrameDemo() {
super("InternalFrameDemo");
final int inset = 50;
final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setBounds(inset, inset, screenSize.width - inset * 2, screenSize.height - inset * 2);
// Set up the GUI.
desktop = new JDesktopPane(); // a specialized layered pane
createFrame(); // create first "window"
setContentPane(desktop);
}
protected void createFrame() {
final JInternalFrame frame = new JInternalFrame("Document #" + ++openFrameCount);
frame.setLocation(xOffset * openFrameCount, yOffset * openFrameCount);
frame.setSize(200, 100);
frame.setVisible(true);
frame.getContentPane().add(createButton());
desktop.add(frame);
try {
frame.setSelected(true);
} catch (final java.beans.PropertyVetoException e) {
}
}
private JButton createButton() {
return new JButton(new AbstractAction("New") {
@Override
public void actionPerformed(final ActionEvent e) {
createFrame();
}
});
}
private static void createAndShowGUI() {
JFrame.setDefaultLookAndFeelDecorated(true);
final InternalFrameDemo frame = new InternalFrameDemo();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public static void main(final String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
createAndShowGUI();
}
});
}
}