Adding jinternalframe class to jdesktoppane using other jinternalframe class

前端 未结 2 1739
独厮守ぢ
独厮守ぢ 2021-01-22 10:59

I\'m creating a very simple program. I have created this classes : MainJframeClass, JDesktopPaneClass, JinternalFrameClass1 and JinternalFrameClass2. what ive done is that i i

2条回答
  •  佛祖请我去吃肉
    2021-01-22 11:54

    how to add the internal2 to desktoppane1 using a button placed somewhere in internal1.

    In the ActionListener added to your button you can use code like the following to get a reference to the desktop pane:

    Container container = SwingUtilities.getAncestorOfClass(JDesktopPane.class, (Component)event.getSource());
    
    if (container != null)
    {
        JDesktopPane desktop = (JDesktopPane)container;
        JInternalFrame frame = new JInternalFrame(...);
        desktop.add( frame );
    } 
    

提交回复
热议问题