• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

prevent + sign to vanish in JTree

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a jtree which is created on 'As needed' basis. i.e, when the user expands the particular node, I make a database call in TreeWillExpandListener and add the children to their parent.
Say, the user has clciked on the + sign besides the node and at that point of time the database is down and I get an exception. when I get the exception, the jtree assumes that there are no children and removes the +. Is it possible to prevent '+' being removed when I get exception from backend?
It would be great if someone has a quick fix for this cos I need this problem to be fixed fast.
Thanks a loot.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Quick fix...

Make a subclass of DefaultTreeModel, override reload() to be public, and override isLeaf() to always return false. Then add a TreeWillExpandListener to the tree to call reload() on the tree model whenever the tree will expand... the current selection is drawn without a '+', but it is added back once the focus changes. This solution may be short term, since constantly reloading the tree will probably cause a slow-down, especially since you are loading your data from a data base... though this should work out fine for testing...

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[OFFTOPIC]
import sun.security.krb5.internal.crypto.d
Using eclipse?
[ January 20, 2003: Message edited by: raj madhuram ]
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oops... yeah...
 
pavan in
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, I have subclass DefaultMutableTreeNode and overridden the isLeaf() to show the + sign.
public boolean isLeaf() {
return !getAllowsChildren();
}
If I call,
((DefaultTreeModel)jtree.getTreeModel()).setAsksAllowChildre(true),
will it do my task?
Thanks.
[ January 21, 2003: Message edited by: pavan in ]
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It will show the '+' the first time, but you will have to keep reloading the tree if you want it to always show the '+' sign.
 
Any sufficiently advanced technology will be used as a cat toy. And this tiny ad contains a very small cat:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic