1

I'm trying for the first time to use and understand JTrees, TreeModels, TreeModes etc. I want to use a Tree to represent Bluetooth devices in the vicinity of my local device. My Bluetooth device is the Root node of the tree and any FIRST descendents from the root node will be Bluetooth devices in the vicinity.

I set up my Tree to begin with as follows (code shortened for brevity):

topTreeNode = new DefaultMutableTreeNode("Local Bluetooth Device");
treeModel = new DefaultTreeModel(topTreeNode);
jTree1 = new javax.swing.JTree(treeModel);

When the JTree is initially displayed the root node reads 'Local Bluetooth Device'. However once I initialise the Bluetooth stack I'd like the root node to display the 'friendly name' and address of my Local bluetooth device.

The problem I have got is just how do I change the root node? I have tried a variety of methods including creating a new DefaultMutableTreeNode() for topTreeNode but the JTree doesn't re-draw straight away. Am I supposed to implement a listener?

2
  • 2
    i think invoking getUserObject() on the root node should get you what you created the node with. If its a custom object and its mutable, you can then set its value :-) Or just setUserObject() could allow you to change it anyways.
    – aishwarya
    Dec 26, 2011 at 17:40
  • Thanks aishwarya. If you post as an answer I'll credit it you with it.
    – D-Dᴙum
    Dec 26, 2011 at 17:57

1 Answer 1

2

as requested, posting this as an answer:

i think invoking getUserObject() on the root node should get you what you created the node with. If its a custom object and its mutable, you can then set its value :-) Or just setUserObject() could allow you to change it anyways.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.