Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

I cannot add a JscrollPane for a Jtree in a Panel for both  RSS feed

 
Mohammad Ashari Rahman
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator





and with the //panelTree.add(tree_1); commented


 
Rob Camick
Ranch Hand
Posts: 2754
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A Swing component can only have a single parent:




First you create a JScrollpane and add the JTree to the scroll pane which is correct.

But then you add the JTree to the JPanel which removes the JTree from the JScrollPane, which is wrong.

Also, don't use setBounds(). Swing was designed to be used with layout managers. The layout manager will determine the size/location of components.

Read the section from the Swing tutorial on How to use Trees for a working example.

If you still have problems then post a proper SSCCE that demonstrates the problem.
 
Mohammad Ashari Rahman
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I solved it by proper setBound arguments.
 
Rob Camick
Ranch Hand
Posts: 2754
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I solved it by proper setBound arguments.



You should NOT be using setBounds().

Swing was designed to be used with layout managers. Learn to use Swing properly and you won't have these problems.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!