| Author |
Jtree without the scroll
|
Tim van Deursen
Greenhorn
Joined: Jul 02, 2003
Posts: 2
|
|
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
Joined: Jan 30, 2002
Posts: 3451
|
|
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 ]
|
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
|
 |
Tim van Deursen
Greenhorn
Joined: Jul 02, 2003
Posts: 2
|
|
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.
|
 |
 |
|
|
subject: Jtree without the scroll
|
|
|