File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jtree without the scroll

 
Tim van Deursen
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to get a Jtree in my program witch will get scrollbars when it expands.
I've placed the Jtree into a scrollpane, but it seems as if the scrollpane doesn't see when the tree expands :?
what am i doing wrong..
Here is some code:
public HoofdVenster() {
super("ProjectX");
this.getContentPane().setLayout(null);
this.getContentPane().add(jScrollPane1, null);
jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
jScrollPane1.setBounds(new Rectangle(18, 24, 280, 290));
jScrollPane1.setVisible(true);
DefaultMutableTreeNode top = new DefaultMutableTreeNode("Translation Engineer"); //Root node not visible
createNodes(top);
final JTree tree = new JTree(top);
tree.setRootVisible(false);
tree.getSelectionModel().setSelectionMode
(TreeSelectionModel.SINGLE_TREE_SELECTION);

test.setText("jEditorPane1");
test.setBounds(new Rectangle(314, 26, 223, 218));
tree.setPreferredSize(new Dimension(20, 20));
jScrollPane1.getViewport().add(tree, null);
this.getContentPane().add(test, null);
[ July 02, 2003: Message edited by: Tim van Deursen ]
 
Michael Morris
Ranch Hand
Posts: 3451
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try creating the tree first and then creating the JScrollPane with one of the constructors that takes a Component. Maybe like this:

Then add the JScrollPane to your content pane.
[ July 02, 2003: Message edited by: Michael Morris ]
 
Tim van Deursen
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Michael Morris:
Try creating the tree first and then creating the JScrollPane with one of the constructors that takes a Component. Maybe like this:

Then add the JScrollPane to your content pane.
[ July 02, 2003: Message edited by: Michael Morris ]


Well believe it or not but i think this was the problem:
tree.setPreferredSize(new Dimension(20, 20));

After i removed it, the scrollpane started to react on the tree.
Thanks anyway, it took me more then two hours to figure it out..
anyway i found it.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic