This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Java in General and the fly likes Jtree without the scroll Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Jtree without the scroll" Watch "Jtree without the scroll" New topic
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jtree without the scroll
 
Similar Threads
JTree not desplaying and check boxes
JTree
JTree not scrolling to selected node
JTree resizing issue
JTable In JTree