A design question regarding an MDI

Hi there - I am still pretty new to Java and am grateful for any help or advice. Here is my question:

I have an MDI application, in which I wish to show orders and order lines from a database in a tree hierarchy.

I have created a JDesktopPane for my MDI as I believe this is what one must do. It is my further understanding that in an MDI, all subsidiary windows should be specified as JInternalFrames. However, as I will wish to use trees very often, I thought it would be a good idea to create a separate class called ObjectBrowser to manage such things. So I have created my class (below), and I pass it both the database I am using and the JDesktopPane object.

The code runs, but my tree window never appears. So I really have two questions:

1. Is my idea of a separate tree class a good one?

2. Could anyone kindly tell me what is wrong with my code as the window never appears, even when I call the method to set it visible.

Many thanks in advance. Here is the code:

package GUI;

import javax.swing.*;

import yio.YDatabase;

// Class: Object Browser - to automate and manage tree objects and the population of them from a database

// NB This class is far from finished as I need to prove the concept first!

publicclass ObjectBrowser{

JInternalFrame yBrowserFrame;

// Create a new instance of ObjectBrowser passing it

// the name of the database we will use if I ever get it to work and also

// the name of the JDesktopPane that I am using for the MDI

public ObjectBrowser(YDatabase yKTDatabase, JDesktopPane yDesktopPane){

yBrowserFrame =new JInternalFrame("Tree");

yBrowserFrame.setContentPane(yDesktopPane);

yBrowserFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JTree tree =new JTree();

JScrollPane yScrollPane =new JScrollPane(tree);

yBrowserFrame.getContentPane().add(yScrollPane);

yBrowserFrame.setSize(250, 250);

}

// Show or hide the browser as required

publicvoid ySetBrowserVisible(boolean ySetBrowserVisible){

yBrowserFrame.setVisible(ySetBrowserVisible);

}

}

[2940 byte] By [Stevew1805a] at [2007-11-27 8:39:11]
# 1
I'm not sure if this will help you, but I find that after adding new objects into a contentpane at runtime to see them you need to run a pack() in the main frame.
drawimagea at 2007-7-12 20:37:03 > top of Java-index,Java Essentials,New To Java...
# 2
I will certainly give this a try - thanks for your thoughts.
Stevew1805a at 2007-7-12 20:37:03 > top of Java-index,Java Essentials,New To Java...
# 3

> I'm not sure if this will help you, but I find that

> after adding new objects into a contentpane at

> runtime to see them you need to run a pack() in the

> main frame.

I am afraid that this didn't appear to work. I added the pack, but to no effect.

Does anyone have any further thoughts? Thanks in advance,

Steve

Stevew1805a at 2007-7-12 20:37:03 > top of Java-index,Java Essentials,New To Java...
# 4
I will add this post into the Swing forum as well, as that may be a more appropriate place.
Stevew1805a at 2007-7-12 20:37:03 > top of Java-index,Java Essentials,New To Java...