buongiorno a tutti,
sto cercando di implementare un interfaccia grafica in java.
l'interfaccia è un frame che ho diviso in due parti: un menù ad albero e un altro frame nel quale vorrei che apparissero le mie classi che seleziono usando il mio albero.
in esecuzione però mi da un eccezione:Exception in thread "main" java.lang.IllegalArgumentException: adding a window to a container

come posso fare?

ecco parte della classe menu:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.event.*;
import java.lang.reflect.*;
import java.util.*;

public class Menu
{
public static void main(String[] args)
{
JFrame frame = new MenuFrame();

frame.show();
}
}

class MenuFrame extends JFrame implements TreeSelectionListener
{
public MenuFrame()
{
setTitle("Menu");
setSize(400,300);
addWindowListener
(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}

}
);


//costruisce l'albero
TreeNode root = makeTree();
model = new DefaultTreeModel(root);
tree = new JTree(model);
//tree.setEditable(true);
//tree.setRootVisible(false);

//imposta modalità di selezione
tree.addTreeSelectionListener(this);
int mode = TreeSelectionModel.SINGLE_TREE_SELECTION;
tree.getSelectionModel().setSelectionMode(mode);


JFrame command = new JFrame();

JSplitPane splitPane;
JPanel albero = new JPanel();
albero.setLayout(new GridLayout(1, 2));
albero.add(new JScrollPane(tree));

splitPane = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT, albero, command );
splitPane.setOneTouchExpandable( true );
splitPane.setDividerLocation( 150 );
splitPane.setContinuousLayout(true);
splitPane.setOneTouchExpandable(true);


//aggiunge riquadro di scorrimento e vi inserisce l'albero
Container contentPane = getContentPane();
contentPane.add(splitPane, "Center");

}
public void valueChanged(TreeSelectionEvent event) {
try
{
String face = tree.getLastSelectedPathComponent().toString();
Class cls = Class.forName(face);
command.add(new JScrollPane((JComponent)cls.newInstance()));
getContentPane().add(command);
}catch(Exception e)

{e.printStackTrace();}

}
public TreeNode makeTree()
{
...........................
}

private DefaultTreeModel model;
private JTree tree;
private JFrame command;
}



vi ringrazio per l'attenzione