File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTree problem

 
Krithika Beri
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an option to browse multiple files. When i browse for a xml file, it appears in jtree form in the pane. When i click on the 2nd opened tree, it is showing the 1st opened tree.



 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not able to understand anything about this problem. Nor does the code explain anything.
You need to TellTheDetails.

you say multiple files, so are you showing each file in a separate tab? does each of this tab show a tree?
 
Krithika Beri
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've got only one pane and in that pane only the JTree is displayed. When i browse for a new file, the old tree is to be replaced by the new tree. The first "browse" method is the ActionListener when you want to browse for a new file. I want to know what probably could be the cause for this error. I think you can ignore the list selection listener that i put there.
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. I see that you add the JScollPane (that has the JTree) to a JPanel named pane2 (I assume pane2 is a JPanel as you have not provided that info).
If so, what is the LayoutManager used for that JPanel? You are adding a new JScrollPane. What about the old one. Should you not remove it first?

Also, why are you using setBounds? I don't think it is needed. Ideally, you should have this pane2 use a BorderLayout with the JScollPane added to the center.
In fact, you should update the tree's model rather than create a new JTree everytime.
 
Krithika Beri
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I only declared the scroll pane earlier, did not initialize it. I am re-initializing it every time. I have a JPanel and in that many other components like a list, tables etc. The tree is a part of it
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic