Solved

jtree population from database

Posted on 2003-11-17
5
819 Views
Last Modified: 2008-02-01
I am trying to build a swing app that loads data into a tree from an oracle database.

The problem seems to be that I can't retrieve all the rows and just build the tree because of the large possibility of a tremendous amount of records.  Instead I thought that I should only initially populate the root nodes and when the user clicks to expand, retrieve the children of that node...and when the node is closed again, clear those objects -- or release the memory somehow.

My problem is I have no knowledge of how to do such a thing and from my searches, there isn't much documentation of an acutal database implementation of populating a jtree and definitiely none regarding dynamic loading / unloading.

So my question (and I'm willing to give away all my points for as much help as possible with this), how can I create a jtree that loads dynamically based on 1) first load (just load root nodes) or 2) clicking on node (load children based on parent value).

Table setup example:
Table.Data
ID //never 0 -- auto increment with each record
ParentID // references ID -- 0 is root.
Date  // Just other values that will
Time // be loaded in Value Object

Any help I would appreciate!
0
Comment
Question by:sapientconceptions
  • 4
5 Comments
 
LVL 92

Expert Comment

by:objects
ID: 9767771
As db query could take some time, you really should do any database queries in a seperate thread  from the event dispatch thread. As doing any time consuming task in the event dispatch thread will block your gui.

To create a tree that dynamically you need to create a custom table model that initiates the database request whenever a node is requested, and caches all db results.
0
 

Author Comment

by:sapientconceptions
ID: 9767911
a custom tree model right (not table)?

Do you have any examples of that and how the nodeClick might call a seperate thread in a SwingWorker?  I have the understanding, I just don't have a complete grasp for the implementation.
0
 
LVL 92

Expert Comment

by:objects
ID: 9767952
> a custom tree model right (not table)?

coorect (woops).

> Do you have any examples of that and how the nodeClick might call a seperate thread

You don't really worry about the node click directly, when the JTree needs data to display it will call your tree model. At this point you can handle initiating your db calls as required.
Shall see what I can find.
0
 
LVL 92

Accepted Solution

by:
objects earned 250 total points
ID: 9767976
0
 
LVL 92

Expert Comment

by:objects
ID: 11054236
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
topping2 challenge 13 83
best (free) software to access postgres db (java) 1 33
bitbucket vs gitbucket 3 58
Java Server Faces parameter pass? 6 39
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

30 Experts available now in Live!

Get 1:1 Help Now