jtree and jtable syn

hello there,

i have a Jtree and a Jtable which gets populated from DB.now how should i implement a feature,so that when i click on a Jtree node,it should highlight the record in the Jtable.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

do you mean somthing like this ?

the tree:
+ row1
   - col1
   - col2

the table:
____    col1    col2
row1   val11   val12
row2   val21   val22

and when you click on col1 on tree then the corresponding cell in table should be highlighted
confirm if im on the right track
zolfAuthor Commented:

for JTree register a TreeSelectionListener through this method addTreeSelectionListener(TreeSelectionListener tsl)
have the nodes of JTree to have row-col indices of themselves in JTable
every time a selection occurs select the proper row-col in the JTable by calling table.changeSelection(row, col, false, false);
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

did you get My idea ?
each JTree node must be aware of its corresponding row and column indexes in JTable
so whenever it gets selected, you know which cell in JTable should be selected correspondingly
zolfAuthor Commented:

can you provide me a small demo with code.if you dont mind.
just as a path on how to do it

// this is used as JTree node
Class Node {
    int row, column; // these two represent the cell that is correspondent to this node
    ... // other values

// register a selection listener
addTreeSelectionListener( new TreeSelectionListener() {
    public void valueChanged(TreeSelectionEvent e)  {
        find the selected tree node
        get the values of row and column from that
        select the corresponding cell from JTable at position [row, col]

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
if you have trouble making JTree nodes point to JTable cells you have still another choice: every time a node in JTree gets selected, search the entire JTable to find an equivalent cell in JTable and highlight it.
my first suggestion needs some preindexing, at the time you populate JTree and JTable, you need to make the interrelations (row,col) and it saves you a lot, by eliminating the search cost in JTable.
you may try either one of these two choice
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.