JPanel
uses FlowLayout
by default which sizes components according to their preferred sizes. You can use BorderLayout
which will use the maximum area possible.
Also using constraints such as BorderLayout.CENTER
has no effect unless the container is actually using BorderLayout
. Dont add
components to the JScrollPane
. This will replaces all components within the view of the component. Instead set the JTextPane
as the ViewPortView
, for example
JPanel panel = new JPanel(new BorderLayout());
JTextPane txt = new JTextPane();
JScrollPane pane = new JScrollPane(txt);
// pane.add(txt); remove
panel.add(pane, BorderLayout.CENTER);
Read: