Java / Netbeans / Swing: No Scrollbar in JTree when dynamically adding nodes to the tree


When dynamically adding items / nodes to a JTree in a Swing application made in Netbeans, the scrollbars do not update or get visible when you add nodes dynamically. The JTree is in a JScrollPane which itself is contained in JSplitplane.

It looks like this:


The problem manifest itself when the Netbeans UI builder added the following line of code for the tree:

jNavTree.setPreferredSize(new java.awt.Dimension(150, 64));

To overwrite this you can easily set the preferred size to null after the "initComponets" call in your code:


After that the scrolling worked as expected:


comments powered by Disqus

Copyright Dunkel & Iwer GbR | Datenschutzerklärung | Impressum