Solved

JTree question

Posted on 2004-03-24
16
497 Views
Last Modified: 2010-03-31
Hi,

I got this problem.  My first page is a JPanel contains a Tree and a Table.  So when I click on the Root of the Tree, it will show Child tree nodes...and then, I choose one of the child nodes, it will show the details of the child node in the table...Now if I want to see more details of a particular items in one child node, I can click on the item in the table and it will go to another page...which is also a JPanel.

Now my problem is if there is an error occurs, it goes back to the first page.  Also, it should go back to the Root but it doesn't.  It shows the item I just chose.  What should I do to go back the Root???  Any suggestion???

Here are my codes..

// adding first page
  TreePanel.add(TreeContainer);
  TreeContainer.setBounds(28, 116, 224, 279);
  TreePanel.add(Table_scrollPane);
  Table_scrollPane.setBounds(262, 116, 473, 277);
  TreePanel.setVisible(true);
  int w = getSize().width;
        int h = getSize().height;
        setSize(w+1, h+1);
        setSize(w, h);
//  and if I got some error messages, I will redo the first page...
  TreePanel.add(TreeContainer);
  TreeContainer.setBounds(28, 116, 224, 279);
  TreeContainer.setVisible(true);
  TreePanel.add(Table_scrollPane);
  Table_scrollPane.setBounds(262, 116, 473, 277);
  Table_scrollPane.setVisible(true);
  TreePanel.setVisible(true);
  int w = getSize().width;
        int h = getSize().height;
        setSize(w+1, h+1);
        setSize(w, h);
0
Comment
Question by:xenia27
[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
  • 5
  • 3
  • 3
  • +2
16 Comments
 

Author Comment

by:xenia27
ID: 10667069
OK...I think I should ask how to make JTree and JTable???  Or any way I can show a Tree struct and its nodes' details...
Any suggestions??
0
 
LVL 37

Assisted Solution

by:zzynx
zzynx earned 100 total points
ID: 10667075
You have to change the selection of your tree to the root again.

Remark:
I see a lot of TreePanel.add()'s.
Don't you forget to remove the items of the treepanel you don't want anymore?
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10667076
>> TreePanel.add(TreeContainer);

Perhaps because you're adding the same TreeContainer, whose state was updated. You want to initialize it again?
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 30

Accepted Solution

by:
Mayank S earned 200 total points
ID: 10667083
0
 

Author Comment

by:xenia27
ID: 10667086
one stupid question...how to remove a Tree Node????
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10667091
>> You have to change the selection of your tree to the root again.

e.g. yourTree.setSelectionInterval(0, 0);
0
 

Author Comment

by:xenia27
ID: 10667096
so should I just call AddFirstPage again???
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10667101
>> one stupid question...how to remove a Tree Node????

Read the java help on this.

void removeSelectionInterval(int index0, int index1)
          Removes the nodes between index0 and index1, inclusive, from the selection.
 void removeSelectionPath(TreePath path)
          Removes the node identified by the specified path from the current selection.
 void removeSelectionPaths(TreePath[] paths)
          Removes the nodes identified by the specified paths from the current selection.
 void removeSelectionRow(int row)
          Removes the row at the index row from the current selection.
 void removeSelectionRows(int[] rows)
          Removes the rows that are selected at each of the specified rows.
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 100 total points
ID: 10667123
>>OK...I think I should ask how to make JTree and JTable???  

You need a TreeTable. Excellent short article here:

http://java.sun.com/products/jfc/tsc/articles/treetable1/


0
 
LVL 92

Expert Comment

by:objects
ID: 10667157
Instead of adding/removing components all the time instead use a CardLayout to easily switch between components.

> one stupid question...how to remove a Tree Node????

remove it from your model
0
 
LVL 92

Assisted Solution

by:objects
objects earned 100 total points
ID: 10667164
Lots of tree and table examples at:

http://www.objects.com.au/java/examples.do
0
 

Author Comment

by:xenia27
ID: 10675119
OK...I'm going to try now...Thanks for the tips.
0
 
LVL 92

Expert Comment

by:objects
ID: 10675506
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10681825
8-)
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10684278
;-)
0
 

Author Comment

by:xenia27
ID: 10684381
^^
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Apache Camel - Unable to propagate JMS Header Properties between Request - Response 3 41
jmss example java 2 48
dao vs facade design patterns 2 72
JDBC performance 8 35
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…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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:
Suggested Courses

751 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