• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How can I put this Jtree into a Split pane

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would like to put a JTree into a splitPane but





Please let me know if you need any further clarifications. Thank you
 
Greenhorn
Posts: 7
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The setLeftComponent method requires a Component as an argument. Your FileBrowser object does not extend the class Component or one of it's subclasses so it is not a Component. A quick look at your code makes me think you may be wanting to use the JTree field in your FileBrowser as the argument for setLeftComponent instead.
 
Marcus Rivera
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alexander Bonasera wrote:The setLeftComponent method requires a Component as an argument. Your FileBrowser object does not extend the class Component or one of it's subclasses so it is not a Component. A quick look at your code makes me think you may be wanting to use the JTree field in your FileBrowser as the argument for setLeftComponent instead.



Thank you for your reply. How do you think I should call the JTree field in FileBrowser so I could put it in the setLeftComponent?
 
Alexander Bonasera
Greenhorn
Posts: 7
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you are calling setLeftComponent from outside the FileBrowser class one option would be to make a public accessor for the JTree field in the FileBrowser class, and then call that accessor as the argument in the setLeftComponent method.
 
Marcus Rivera
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alexander Bonasera wrote:Since you are calling setLeftComponent from outside the FileBrowser class one option would be to make a public accessor for the JTree field in the FileBrowser class, and then call that accessor as the argument in the setLeftComponent method.



So i made Jtree tree public in the FileBrowser class

I did [ FileBrowser testing=new FileBrowser();]


and then did[ splitPane.setLeftComponent(testing.tree);]

Did I do it correctly because it does not seem to be doing anything
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Marcus Rivera wrote:...because it does not seem to be doing anything



That could cover a multitude of sins. Could you perhaps be more specific about what it isn't doing? I'm sure there is a list of things you expected to see; surely you are seeing some of them? On the other hand if you don't see any of the GUI at all then it would help if you said so.
 
Paul Clapham
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just looked a bit more at your code. If I read it right, it's supposed to be filling a JTree with all of the files on your C drive. The last time I looked, my Windows C drive had over a quarter of a million files on it. So you might just have to wait longer for your table to appear. Or maybe you're getting an out-of-memory error. Are you running your code in such a way that you can see if it writes output (e.g. stack trace) to the console?

P.S. I'm going to move the thread to the Swing forum.
 
Saloon Keeper
Posts: 15524
364
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's probably because you are also adding the tree to a scroll pane. A component can have only one parent.

Don't make the field public. Just add the JTree to a JScrollPane, add the JScrollPane to a JSplitPane, and add the JSplitPane to the JFrame.

If it's still not working, show us the code including where you've tried to add the JTree.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This as been asked in other forums: https://stackoverflow.com/questions/60291922/how-can-i-put-this-jtree-into-a-split-pane

The OP has just completely reposted the same question without attempting to implement any of the suggestions given.




 
Marcus Rivera
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:It's probably because you are also adding the tree to a scroll pane. A component can have only one parent.

Don't make the field public. Just add the JTree to a JScrollPane, add the JScrollPane to a JSplitPane, and add the JSplitPane to the JFrame.

If it's still not working, show us the code including where you've tried to add the JTree.



This worked perfectly, thank you very much
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
MR: please don't edit a post to add so much information. Please put the new class in a new post. I have reverted the changes.
 
reply
    Bookmark Topic Watch Topic
  • New Topic