• Post Reply Bookmark Topic Watch Topic
  • New Topic

new JScrollPane(comp) and pane.add(comp)

 
Anthony Yulo
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<p>
I'm trying to add a JTree in my program... of course i have properly created a new JTree... now
when i initialized a JScrollPane and added the Jtree to it like this:

when i use this code the tree doesn't appear in my GUI. However when i make the creation of JScrollPane and adding of the component in one line as in this code:

my tree appears in the GUI...
I'm wondering what's the difference between the two code...

</p>
 
Horaci Macias
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try pane.setViewportView(myTree); instead of add.
 
satya sahu
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
It is the veiwPort Problem.Try the following code
JScrollPane scroll = new JScrollPane();
scroll.getViewport().setBackground(Color.white);
scroll.getViewport().add(tree);
The reason for setting the color of the viewport and not the scrollpane is that by default JViewport is opaque which, among other things, means it will completely fill in its background using its background color. Therefore when JScrollPane draws its background the viewport will usually draw over it. So the tree is also drawn.
 
Anthony Yulo
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tnx.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!