Salve a tutti, come da titolo sto avendo un problema a gestire un JPanel scrollabile.
Ho trovato esempi online in cui viene creato un JScrollPane che occupa tutto il JFrame, mentre nell' esempio che posto sotto, io vorrei rendere scrollabile il pannello denominato "centroSud".

Il problema è che la barra si forma se imposto come regola la sua presenza obbligatoria,
se invece chiedo che compaia quando necessario e aggiungo componenti al pannello in eccesso, la barra non si crea.Ecco il codice :

codice:
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
public class Scroll extends JFrame
{
    public static void main(String[] args)
    {
        JFrame frame=new JFrame("Esempio Scroll");
        frame.setSize(700,681);        
        frame.setLocation(20,20);    
        frame.setResizable(false);        
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container finestra=frame.getContentPane();
        finestra.setBackground(Color.WHITE);
        JPanel nord=newPanel(new JPanel(),700,110,Color.GREEN);
        JPanel ovest=newPanel(new JPanel(new BorderLayout(0,0)),442,540,Color.ORANGE);        
        JPanel centro=newPanel(new JPanel(new BorderLayout(0,0)),258,540,Color.WHITE);
        JPanel centroNord=newPanel(new JPanel(),258,200,Color.BLUE);
        JPanel centroSud=newPanel(new JPanel(new FlowLayout(SwingConstants.CENTER,0,0)),258,340,Color.RED);        
        JScrollPane lista=new JScrollPane(centroSud);
        lista.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        lista.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);    
        for(int i=0;i<20;i++)centroSud.add(newLabel("Scritta","",258,20));
        finestra.add(nord,BorderLayout.NORTH);
        finestra.add(ovest,BorderLayout.WEST);
        finestra.add(centro,BorderLayout.CENTER);
        centro.add(centroNord,BorderLayout.NORTH);
        centro.add(lista,BorderLayout.SOUTH);
        frame.setVisible(true);
    }
    public static JPanel newPanel(JPanel p,int h,int v,Color c)
    {
        p.setPreferredSize(new Dimension(h,v));
        p.setOpaque(true);
        p.setBackground(c);
        return p;
    }
    public static JLabel newLabel(String text,String align,int h,int v)
    {
        int a=SwingConstants.CENTER;
        if(align.equalsIgnoreCase("left"))a=SwingConstants.LEFT;
        else if(align.equalsIgnoreCase("right"))a=SwingConstants.RIGHT;
        JLabel l=new JLabel(text,a);
        if(h>0&&v>0)l.setPreferredSize(new Dimension(h,v));        
        return l;
    }
}
In particolare a me mostra 17 delle 20 label di prova che ho aggiunto, le ultime tre vengono nascoste senza che si aggiunga la barra di scorrimento.

Grazie per l'aiuto !