Reputation:
I have been working on a JFrame
, which contains a panel of multiple components. However, the frame cannot accommodate all components due to its size. I wish to use a scrollable frame, and came across a link where JScrollPane
use is suggested. However, when the frame is resized, the scroll pane container does not take up the size of the resized frame.
Is there a way to achieve this?
Upvotes: 0
Views: 3539
Reputation: 324078
By default a JFrame uses a BorderLayout. When you add a component to the CENTER
of the BorderLayout the component will take all the available space of the frame.
So the basic logic is:
JPanel panel = new JPanel(...);
JScrollPane scrollPane = new JScrollPane( panel );
frame.add(scrollPane, BorderLayout.CENTER);
Upvotes: 5
Reputation: 303
Set the frame to use grid layout. Gridlayout makes all of the components in the frame use up the entire size.
Container contentPane = frame.getContentPane();
contentPane.setLayout(new GridLayout(1,1));
Upvotes: 1