I'm building a Swing application in Java using NetBeans and I have a problem with layout. My main frame contains a JScrollPane
which contains a JPanel
called contentPanel
which in turn contains a JPanel
called listPanel
. The listPanel
is empty when the program starts, but when the user interacts with the program an unpredictable number of smaller JPanel
s are added to it. I've used the NetBeans GUI-builder to snap the top edge of listPanel
to the top of contentPanel
, and the same with the bottom edges.
The problem I have is that when more components are added to listPanel
the vertical scrollbar doesen't appear on my scrollpane. The verticalScrollBarPolicy
of my scrollpane is set to AS_NEEDED
and its viewportView
is set to contentPanel
. What I think I need to do is to make contentPanel
grow when more items are added to listPanel
.