Help coderanch get a
new server
by contributing to the fundraiser
  • 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

re: adding JScrollPane to Jtree

Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there. I am having a slight problem trying to add a JScrollPane to my Jtree. Is it a case that The ScrollPane appears only if it is required, i.e. when the tree has been expanded sufficiently enough so that further space in the panel is required to accomodate this expansion. My code is as follows(just a snippet):
private JTree tree;
private JPanel newPanel;
public addJTree(String option)

public JTree createTree()
DefaultMutableTreeNode top = new DefaultMutableTreeNode("Features");
createNodes(top); //this simply adds the children and gives no hassle
tree = new JTree(top);
JScrollPane treeView = new JScrollPane(tree); //no scroll pane appears
treeView.createVerticalScrollBar(); //dont know if this is necessary
return tree;
public JPanel getGUI()
//create a panel containing the associated Swing component
newPanel = new JPanel();
//JScrollPane scroll = new JScrollPane(newPanel);
return newPanel;
Can anyone see the problem. Any help is much appreciated. Thanks Joe
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Scroll down to the methods and find setVerticalScrollBarPolicy and setHorizontalScrollBarPolicy.
Quick! Before anybody notices! Cover it up with this tiny ad:
We need your help - Coderanch server fundraiser
    Bookmark Topic Watch Topic
  • New Topic