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

