Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

re: adding JScrollPane to Jtree  RSS feed

 
joew weakers
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • 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
 
Peyton McCullough
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!