-1

How do I add the JDesktopPane to JFrame using GridBagLayout and set its height and width. If I add JDesktopPane that contains JInternalFrame I don't get anything. But works well in case of GridLayout but the problem is I can't set my desired size in it as GridLayout splits equal space among each component added.

Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
Praburaj
  • 613
  • 8
  • 21

1 Answers1

3

You will probably need to set the fill and weight attributes of the GridBagConstraints...

GridBagConstraints gbc = new GridBagConstraints();
gbc.weightx = 1;
gbc.weighty = 1;
gbc.fill = GridBagConstraints.BOTH;

This will cause the component to want to push to the limits of the container and will cause the component to fill it's cell within the grid

This override the components preferred size (for the most part)

Take a look at How to Use GridBagLayout for more details...

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • When I try adding another component it just comes on top of the first component. What can cause such problem. I have clearly mentioned the gridx and gridy constraints in my code. – Praburaj Apr 04 '14 at 22:58
  • Start by reading the linked tutorial. You will probably also need to supply `gridx` and `gridy` properties. – MadProgrammer Apr 04 '14 at 23:00
  • I have supplied those properties. gridx = 0 and gridy = 0 for the first component and gridx = 1 and gridy = 0 for the second component. – Praburaj Apr 04 '14 at 23:09
  • With out a [runnable example](https://stackoverflow.com/help/mcve) there's not much more that I can suggest – MadProgrammer Apr 04 '14 at 23:11