JScrollPane not showing the scroll bars inside a JSplitPane
<p>I have this piece of code that is basically a JFrame that contains a JSplitPane which contains on the left side a JScrollPane which contains a JPanel. I expected to see the scroll bars since the JPanel inside the JScrollPane is larger that the JScrollPane itself. Why are the scroll bars not displayed?
If I replace setSize() with setPreferredSize() then it works, but I want to use setSize(). Is there any way I can use setSize() and have the scroll bars showing?</p>

<pre><code>import java.awt.*;
import javax.swing.*;

public class Test {

    public static void main( String[] args ) {
        JFrame frame = new JFrame();
        frame.setLayout( new BorderLayout() );
        JSplitPane splitPane = new JSplitPane();
        frame.add( splitPane, BorderLayout.CENTER );
        JPanel panel = new JPanel();
        panel.setBackground( Color.red );
        panel.setSize( 1920, 1200 );
        //panel.setPreferredSize( new Dimension( 1920, 1200 ) );
        JScrollPane scrollPane = new JScrollPane( panel );
        splitPane.setLeftComponent( scrollPane );
        splitPane.setRightComponent( new JPanel() );
        frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        frame.pack();
        frame.setVisible( true );
        frame.setSize( 960, 600 );
    }
}
</code></pre>

<p>Edit: I've added a modified version where I use setPreferredSize(). Is there a better solution for dynamically changing the size?</p>

<pre><code>import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Test {

    public static void main( String[] args ) {
        JFrame frame = new JFrame();
        frame.setLayout( new BorderLayout() );
        JSplitPane splitPane = new JSplitPane();
        frame.add( splitPane, BorderLayout.CENTER );
        final JPanel panel = new JPanel();
        panel.setBackground( Color.red );
        panel.setPreferredSize( new Dimension( 1920, 1200 ) );
        JScrollPane scrollPane = new JScrollPane( panel );
        splitPane.setLeftComponent( scrollPane );
        JButton button = new JButton();
        button.addActionListener( new ActionListener() {

            @Override
            public void actionPerformed( ActionEvent e ) {
                panel.setPreferredSize( new Dimension( 3840, 2400 ) );
                panel.revalidate();
            }
        });
        splitPane.setRightComponent( button );
        frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        frame.pack();
        frame.setVisible( true );
        frame.setSize( 960, 600 );
    }
}
</code></pre>