?
Solved

jtree population from database

Posted on 2003-11-17
5
Medium Priority
?
849 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 total points
ID: 9767976
0
 
LVL 92

Expert Comment

by:objects
ID: 11054236
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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 tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
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 …
Suggested Courses
Course of the Month8 days, 15 hours left to enroll

764 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