Solved

jtree population from database

Posted on 2003-11-17
5
817 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
Comment Utility
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
Comment Utility
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
Comment Utility
> 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
Comment Utility
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This video teaches viewers about errors in exception handling.

762 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

7 Experts available now in Live!

Get 1:1 Help Now