JDesktopPane, JInternalFrame, and TopComponent

Based on a question on the dev mailing list, I'm trying to create one or more TopComponents that are constrained within their mode. I guess that would require some special kind of mode that currently does not exist. (But can new Mode implementations be registered with the WindowManager and, if so, how?) Or a new WindowManager. I got it working with JDesktopPane and JInternalFrame, as can be seen here:

However, it would be better if the JInternalFrames were to be TopComponents instead. Any clues?

Here's how I created the above TopComponent:

...
...
...

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

}

...
...
...

Hope someone has ideas on how to use TopComponents instead of JInternalFrames in this scenario!

Comments:

Not sure if this really fixes you problem here but I have posted about managing JInternalFrame parent/child hierarchy which may give some tips to your problem!

Posted by Steve Webb on March 12, 2011 at 07:08 PM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today