Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何从netbeans中的另一个内部帧打开内部帧_Java_Swing_Netbeans - Fatal编程技术网

Java 如何从netbeans中的另一个内部帧打开内部帧

Java 如何从netbeans中的另一个内部帧打开内部帧,java,swing,netbeans,Java,Swing,Netbeans,我在主框架中创建了一个内部框架,我想从旧框架中打开另一个内部框架 我不知道怎么做。有什么建议吗 我尝试了许多不同的方法来打开另一个内部框架: 我使用了setVisible(true)方法,但它不起作用 我创建了大型机的对象,但没有得到正确的方法 我在谷歌上搜索了它,搜索了Stack Overflow,但没有找到任何答案。好吧,你可以从Java教程开始 但一个可能的过程可能是 JInternalFrame newFrame = JInternalFrame(); newFrame.setBou

我在主框架中创建了一个内部框架,我想从旧框架中打开另一个内部框架

我不知道怎么做。有什么建议吗

我尝试了许多不同的方法来打开另一个内部框架:

  • 我使用了setVisible(true)方法,但它不起作用
  • 我创建了大型机的对象,但没有得到正确的方法

我在谷歌上搜索了它,搜索了Stack Overflow,但没有找到任何答案。

好吧,你可以从Java教程开始

但一个可能的过程可能是

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

好的,您可以从Java教程开始

但一个可能的过程可能是

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

你可以这样做:

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();
            }
        });
    }
}

改编

您可以这样做:

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();
            }
        });
    }
}

先生,我试过这个代码,但不起作用。我创建了一个内部框架。我在上面创建了一个按钮。还有一个内部框架。当我点击按钮时,我想打开另一个内部框架。单击按钮时,我编写了您告诉我的方法,但我没有使用。请向我们提供一些示例代码,包括您试图添加到的容器-我怀疑您可能没有使用JDesktopPane或LayoutManager。不要忘了
pack()
:-)@CatalinaIsland虽然我同意,但在正常情况下,打包是一个好主意,但它可能会导致一个大小为0x0的帧,当我放置CurrentFrame.SetVisible(false)时,实际上隐藏了该帧Sir,然后上面的工作正常。最后我找到了解决方案,谢谢你。先生,我试过这个代码,但没有成功。我创建了一个内部框架。我在上面创建了一个按钮。还有一个内部框架。当我点击按钮时,我想打开另一个内部框架。单击按钮时,我编写了您告诉我的方法,但我没有使用。请向我们提供一些示例代码,包括您试图添加到的容器-我怀疑您可能没有使用JDesktopPane或LayoutManager。不要忘了
pack()
:-)@CatalinaIsland虽然我同意,但在正常情况下,打包是一个好主意,但它可能会导致一个大小为0x0的帧,当我放置CurrentFrame.SetVisible(false)时,实际上隐藏了该帧Sir,然后上面的工作正常。最后,我找到了解决方案,谢谢Guid。要更快地获得更好的帮助,请发布。要更快地获得更好的帮助,请发布。