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
Solved

jtree population from database

Posted on 2003-11-17
5
830 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

856 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