• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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)
{
super(option);
createTree();
}

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();
newPanel.add(tree);
//JScrollPane scroll = new JScrollPane(newPanel);
//newPanel.add(treeView);
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
http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JScrollPane.html
Scroll down to the methods and find setVerticalScrollBarPolicy and setHorizontalScrollBarPolicy.
 
He does not suffer fools gladly. But this tiny ad does:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic