Reputation: 121
I am trying to set a JPanel fill the whole window of a JFrame. The layout of JPanel is GridBagLayout. If i change it to BorderLayout it works. But i need the GridBagLayout and in this way the JPanel appears on the Center of the window. How can i fill the whole window of JFrame with the JPanel( just like with BorderLayout )?
Upvotes: 0
Views: 57
Reputation: 347184
First, make sure you read How to Use GridBagLayout
Next, make sure you have the JavaDocs for GridBagConstraints open and available
These two basic references will provide you with 99% of the information you need to answer just about most of you issues.
Without more context, something like...
GridBagConstraints gbc = new GridBagConstraints();
gbc.weightx = 1;
gbc.weighty = 1;
gbc.fill = GridBagConstraints.BOTH;
will achieve the result you're looking for
Remember though, you are not stuck to a single layout manager, you can use multiple containers all using different layout managers to achieve your desired results
Upvotes: 2