0

I created class NewProject extends JInternalFrame. Then I create New...Action named "NEW", localised in File menu. I put code NewProject p = new NewProject(); p.setVisible(true); to the ActionPerformed method of the action.

But when I run the module and click "NEW" in file menu, nothing appears. Where can be problem?

EDIT: I partially solved it by code:

public void actionPerformed(ActionEvent e) {

    JInternalFrame f = new JInternalFrame();
    f.setSize(500, 500);
    f.setVisible(true);
    JDesktopPane p = new JDesktopPane();
    p.add(f);

   //WindowManager.getDefault().getMainWindow().setTitle("fFF");
   WindowManager.getDefault().getMainWindow().add(p)

}

but GUI is broken. When I create new internal frame, the black background appears as I move by that frame. Any idea how to solve it?

joseph
  • 687
  • 3
  • 12
  • 21
  • Could you explain a little bit more what do you want to achieve? – Enrique Mar 13 '10 at 23:39
  • I want create internal frame in netbeans platform. When I run module and select action which create that internal frame, I want that frame appear – joseph Mar 14 '10 at 00:06
  • You should first create a top level container like JFrame and then add the JInternalFrame within the JFrame. – Enrique Mar 14 '10 at 00:11
  • but toplevel container is created by netbeans and I cannot find how to get to it. – joseph Mar 14 '10 at 00:39

2 Answers2

2

The customary Container for JInternalFrame is JDesktopPane. The article How to Use Internal Frames outlines the essentials, and you may like this short example of using Action and JMenu in this context.

Although the NetBean's GUI editor is appealing, you may want to become more comfortable using Swing components first.

Addendum: You can't add one Top-Level Container like JFrame to another like JDesktopPane, but you can add any number of JInternalFrame instances to a JDesktopPane. Try the demo to see how it works.

Addendum: Ah, you mean NetBeans Platform. Sorry, I've not used it.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • But the problem is I do not know how to get main window's desktoppane or whatever where I can attach my JFrame. I am speaking about Netbeans Platform. – joseph Mar 14 '10 at 01:43
  • Sorry about the broken tutorial link. See above for more. – trashgod Mar 14 '10 at 02:33
  • I am not sure If you understand me (i am not english speaking). I know how to create internal frame when I create my own main window. But I do not know how to get my internal frame into pre-created main window of Netbeans Plaform – joseph Mar 14 '10 at 02:38
1

I think the answer you are looking for is here: https://blogs.oracle.com/geertjan/jdesktoppane,-jinternalframe,-and-topcomponent

There Geertjan Wielenga show an example using a TopComponent with a JDesktopPane inside, where you can attach some JInternalFrame.

...
...
...
private JDesktopPane jdpDesktop;
private int openFrameCount = 0;
public DemoTopComponent() {
    initComponents();
    setName(NbBundle.getMessage(DemoTopComponent.class, "CTL_DemoTopComponent"));
    setToolTipText(NbBundle.getMessage(DemoTopComponent.class, "HINT_DemoTopComponent"));
    setLayout(new BorderLayout());
    jdpDesktop = new JDesktopPane();
    createFrame(); // Create first window
    createFrame(); // Create second window
    createFrame(); // Create third window
    //Add the JDesktop to the TopComponent
    add(jdpDesktop);
}
protected void createFrame() {
    MyInternalFrame frame = new MyInternalFrame();
    frame.setVisible(true);
    jdpDesktop.add(frame);
    try {
        frame.setSelected(true);
    } catch (java.beans.PropertyVetoException e) {
        }
 }

class MyInternalFrame extends JInternalFrame {
    int xPosition = 30, yPosition = 30;
    public MyInternalFrame() {
        super("IFrame #" + (++openFrameCount), true, // resizable
            true, // closable
            true, // maximizable
            true);// iconifiable
        setSize(300, 300);
        setLocation(xPosition / openFrameCount, yPosition /   openFrameCount);
        // Add some content:
        add(new JLabel("hello IFrame #" + (openFrameCount)));
       }
}
...
...
...
g00glen00b
  • 41,995
  • 13
  • 95
  • 133
Baaden
  • 11
  • 2
  • Can you at least provide an example of how that was done? If that link disappears in X years time, and someone comes across this question with the hopes of finding a solution, will your post provide them with a solution? By adding the relevant example, the quality of your answer goes from 0(should have been a comment) to 10(an actual answer/solution) – Frits Jul 24 '17 at 08:21
  • 1
    Ah perfect - you finished your edit as I posted my comment. I am retracting my flag, and +1. This is what an answer should look like. Well done. – Frits Jul 24 '17 at 08:21
  • @user8356314 Same here, I retracted my flag and deleted my previous comments (which are now irrelevant). – g00glen00b Jul 24 '17 at 08:25