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.

I did have some doubt that this might work as I am trying to place an InternalFame into a DesktopPane which has been created in another class, but I thought I would give a try anyway as I imagine it would be very useful.

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!

public class 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

public void ySetBrowserVisible(boolean ySetBrowserVisible){

yBrowserFrame.setVisible(ySetBrowserVisible);

}

}

[2403 byte] By [Stevew1805a] at [2007-11-27 8:39:16]
# 1

For the sake of all that is code worthy, please dont start every variable name with 'y'. it makes the code quite hard to read.

You've sorta reversed the code. The JInternalFrame needs to be added to the JDesktop pane not the other way around.

yBrowserFrame = new JInternalFrame("Tree");

yBrowserFrame.setContentPane(yDesktopPane);

could rather be

yBrowserFrame = new JInternalFrame("Tree");

yDesktopPane.add(yBrowserFrame);

Secondly, are you sure you call the setBrowserVisible method?

If possible, re-post the example and make it a complete working one that demonstrates the problem. This code is only half complete.

icewalker2ga at 2007-7-12 20:37:09 > top of Java-index,Desktop,Core GUI APIs...
# 2
That's great. My code is now working - thank you very much for your time and thoughts.Steve
Stevew1805a at 2007-7-12 20:37:09 > top of Java-index,Desktop,Core GUI APIs...