?
Solved

jtree and jtable syn

Posted on 2006-04-21
7
Medium Priority
?
498 Views
Last Modified: 2008-03-17
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.

cheers
zolf
0
Comment
Question by:zolf
  • 5
  • 2
7 Comments
 
LVL 14

Expert Comment

by:hoomanv
ID: 16513922
do you mean somthing like this ?

the tree:
+ row1
   - col1
   - col2
+row2
   -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
0
 

Author Comment

by:zolf
ID: 16513997

yes
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 16514018
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);
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 14

Expert Comment

by:hoomanv
ID: 16514034
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
0
 

Author Comment

by:zolf
ID: 16514099

can you provide me a small demo with code.if you dont mind.
0
 
LVL 14

Accepted Solution

by:
hoomanv earned 1000 total points
ID: 16514158
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]
    }
})
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 16514226
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
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This video teaches viewers about errors in exception handling.
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 Month15 days, 13 hours left to enroll

850 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