-1

I need to resize components when the user resizes the window.

I think this is very easy with GridBagLayout, using the weight properties and fill property to both.

However, I was wondering can I do the same in other layouts?

Does anybody know a way to resize components in all layouts?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
pguzman
  • 105
  • 1
  • 1
  • 7
  • 1
    It is obviously very layout specific. Some layouts don't change the size of components on window resize. – Ashwinee K Jha Feb 04 '13 at 16:25
  • 1
    See [this answer](http://stackoverflow.com/a/7181197/418556) for two very easy ways to stretch a component to fill the size of the parent container (using `BorderLayout` & `GridLayout`). – Andrew Thompson Feb 04 '13 at 16:44
  • 1
    How components are sized (or not) is a feature (in fact, **the** primary feature) of any given layout manager. Read the docs for the layouts to find out which does what. – millimoose Feb 04 '13 at 16:49

1 Answers1

1

You might compare the two contrasting examples shown here. Both make the size of two flanking borders proportional to the central panel.

  • The first, uses GridBagLayout.

  • The second uses a ComponentListener.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045