JTree: What do I do, when a leaf node isn't a leaf node?

Hi All,
I have a question about the JTree and leaf nodes.
My requirements are:
1) I have to have a tree which doesn't "fill" its contents at a certain level until the user expands a node
2) As a result of #1, leaf nodes must have a "+" sign in front of them until the user tries to expand them at least once (if they are then empty, the "+" is removed in favor of the normal leaf icon.. if they have data, the "+" is replaced with a "-" and the data is filled in)..
Currently, we have an implementation of this which adds a "dummy" node as a child of the leaf to force it to be a "non-leaf", until the user opens it, then the dummy object is removed and the real data (if any) is added..
It works, but I'm wondering if there is a simpler way.
Can anyone offer their opinion? Thanks a bunch.
Dave

What I do is to have some code that implements TreeWillExpandListener. What happens then is that when the user clicks on the doohickey to expand a node, my treeWillExpand(TreeExpansionEvent e) method is called. It examines the node that is about to expand and goes out to the database to load up its children. But to make this work, you have to have the doohickey available. This means that your nodes have to know whether their children have been loaded or not; this is the code I use to override the isLeaf() method for them:public boolean isLeaf() {
  return (childrenLoaded ? super.isLeaf() : false);
}In this code "childrenLoaded" is a boolean instance variable that is initialized to false, then set to true via a property-setter method by the code that loads the node's children.
That's a rough outline of what I did. Good luck!

Similar Messages

Maybe you are looking for

  • I JUST CAN'T BELIEVE IT !

    I have posted a question about using an external bootable drive on this forum. One answer was coming at the time I called Apple Care for which I paid to go with my IMAC. After spending a LONG time dealing with an incompetent person acting as a filter

  • How to change 'z' key into 'A' key with key blinding?

    How to change 'z' key into 'A' key? Although txt.setText("A") can set the text field with 'a', but it is not original input from keyboard because it cant trigger the key listener. It is possible to perform key pressing more than a key in same time? E

  • Content protection

    Content protection is enabled, how do I undo this?

  • Alternative for Continue Statement in 10g

    Best way to write below code in Oracle 10g (as continue does not exist) BEGIN FOR i IN 1..10 LOOP Dbms_Output.put_line(i); CONTINUE  WHEN i>5; CASE Dbms_Output.put_line(i); END LOOP;

  • After offer release, employee has to fill personal details through URL-E-recruitment

    Dear All, Client is Indian, After Offer release through e-recruitment. HR want to send URL mail to selected candidate. Through this URL candidate has to fill all personal details(Family details, IT Declarations, Blood group etc.) How to store this da