Java Swing JTree update content


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Java Swing JTree update content

  1. #1
    Join Date
    Oct 2004
    Posts
    311

    Java Swing JTree update content

    Hello all,

    I've got the following problem:
    I have a Jtree, which is in the left side of my JSplitPane. When I select an item in the tree, I get the option to edit it in the Right part of the SplitPane. Everything works fine so far. Once I editted the item, I pres the save button, which puts my updated item into the database (works fine) and updates the tree to represent the new item. This last part is where the problems begin. The text of the item is not updated. Once I select a different item in the tree the text of the changed Item changes, but I can't figure out how to change it while the text is selected.

    Any help would be appreciated.

    Mark

  2. #2
    Join Date
    Mar 2004
    Posts
    635
    Try looking at this method.

    protected void fireValueChanged(TreeSelectionEvent e)

    What's happening is that the tree isn't being redrawn until you've selected a new item.

  3. #3
    Join Date
    Oct 2004
    Posts
    311
    great, will do.
    now to find a way to call it from outside the tree....

    I've already tried setting the selection to a different item, calling repaint() and resetting the selection with no effect

  4. #4
    Join Date
    Aug 2003
    Posts
    313
    What people usually do for things like this is subclass the TreeModel with their own model. Then you expose the model and give it methods like changeData() or something that do exactly what you want them to do and then call the fire... events. You will want to subclass the DefaultTreeModel so that you dont' have to write all of the stuff, but make sure that you override some of the methods if you need to.

    Hope this helps.
    ~evlich

  5. #5
    Join Date
    Oct 2004
    Posts
    311
    I was hoping to avoid having to do this. But it looks like I have no choice. Oh well...

    Btw. The program I'm currently working on is becoming bigger and bigger, so I could really use some help, if people are interested, send me a PM. The program is (currently) a character generator for the DnD pen and paper Roleplaying Game. But the goal is to make it compatible with all D20 RPGs, and add conline gaming functionality as well.

    Mark

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center