real love and dating - Jtree not updating

You cannot keep on resizing the frame in order to update your tree.---- When you add dynamically nodes, they are added to the structure of nodes.

jtree not updating-10

The update to the tree (or the tree nodes) is taking place as a result of a thread that periodically retrieve the current system status and updates the tree.

The tree does not get updated based on any mouse clicks on the tree itself. Does that mean that when I create the DMTNs, I'll need to pass in the DTM handle to every single DMTN?

Why can't the DMTN say "to the tree I am part of, can you please give me your model?

" (I guess java doesn't offer the above ability.) 2. The question I have left is how to pass it around to the various DMTNs. Finally, I'm having a problem grasping the separation between the data and the GUI.

This is a bad design decision, but won't hurt the program itself.

Generally, it is enough that you keep a reference to a normal (not your custom) mutable root tree node and add/remove children whenever you wish. Component listener on resize does help to make the JTree update, however this is far from doing the correct thing.However, if the CL is not viable, then I guess I'll have to use TL Thank you // ============== Test BEGIN ===================== package Children; import *; import event.*; import java.applet.*; import javax.swing.*; public class Test Applet extends JApplet // =============== Test END ====================== // ============== Second BEGIN ===================== package Children; import *; import javax.swing.*; import javax.*; import event.*; public class Second Page extends JPanel // =============== Second END ====================== // ============== My Tree BEGIN ===================== package Children; import javax.*; public class My Tree Node extends Default Mutable Tree Node // =============== My Tree END ====================== Ok then, Since your updates are insiped by a separate thread, your program should store references and find about the nodes by walking the tree. The nodes (DMTN) does not need to know about the model (DTM).Just, when you need to modify tree content instant update, use the reference of the model to add/remove nodes from their parents. And you can always obtain the model if you have the reference to the JTree.Thus, you better use the methods of DTM (you can keep a reference to it from initialisation time when you passeed it to the JTree constructor) insert Node Into and delet Node From. When your tree modifications are based on the selection or a mouse click within the tree (event related to the tree itself), there are standard methods to determine which is the selected node.NOTE THAT the DTM does not keep any information about structure of the tree! Thus, you can obtain a reference to the particular DMTN and then look for a particular child, or its parent.If you don't want to use a Tree Model (although in you code you of course ARE using a Tree Model, you just don't see it) you could maybe solve the problem by letting the root node have a referemce to either the JTree or (as shown in the next parts of the code) a Default Tree Model: changed in jb Init: root Node = new My Tree Node(); // the next line is also done inside the constructor of JTree if you specify a node instead of // Tree Model Default Tree Model model = new Default Tree Model(root Node) If you are reluctant to use tree model, you need to implement the same functionality the Default Tree Model implements in order to be able to dynamically add nodes to the tree.

Tags: , ,