You can use BorderLayout
which will make the JScrollPane
occupy the full area of the JPanel
JPanel panel = new JPanel(new BorderLayout());
The default JPanel layout, FlowLayout
, uses a component's preferred size which will not expand to fill the window.