Solved

jtree population from database

Posted on 2003-11-17
5
839 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 250 total points
ID: 9767976
0
 
LVL 92

Expert Comment

by:objects
ID: 11054236
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
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.

691 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