I try to have a main class that calls TreeList.java, which will call another class FileTree.java . However, when I run the program, it came out as two separate window.
How can I make it in one window ? I tried to put leftPanel.add(fileTree, "FileTree"); in my TreeList.java but it didn't work. Anyone can help? Thanks
Why not have your FileTree either subclass a JPanel, or (my preference) extend JPanel functionality by composition, rather than have it subclass a JFrame?
Joined: Dec 04, 2009
Hi Pete, thanks for the headstart. Sorry, but have a question that may sound stupid.. I do not understand how I should go about, meaning I change my FileTree to extend JPanel instead? From there, how can I go about to call the JFrame functions?
Joined: Feb 23, 2007
Wynn Teoh wrote:Hi Pete, thanks for the headstart. Sorry, but have a question that may sound stupid.. I do not understand how I should go about, meaning I change my FileTree to extend JPanel instead?
To be honest, my GUI code never subclasses JFrame and only rarely subclasses JPanel, usually when I need to override one of JPanel's methods such as paintComponent. In this situation, I would gear my class to create a JPanel and then make that JPanel available to other classes using this one, perhaps via a getPanel() method that I create. Doing it this way helps prevent me from shooting my foot, like I've done in the past when I accidentally overrode JPanel's getX() and getY() methods. This is off the subject of your main question, and you'll likely be able to get by with extending JPanel, but I feel obliged to mention this.
From there, how can I go about to call the JFrame functions?
Why does this class need to have a window listener? What purpose does it serve? If absolutely necessary, you could always have a public method in this class that you have your WindowListener call.