Ian Renton
Ian Renton

Reputation: 729

How do I programatically resize a component in a BorderLayout?

I have a JPanel that is located at the BorderLayout.SOUTH position of a parent JPanel. I would like to programatically change the height of this child JPanel.

I am calling childPanel.setPreferredSize(new Dimension(getWidth(), newHeight));, but it has no effect. (I have tried setting the Maximum and Minimum sizes as well.)

What (probably very simple thing) am I missing?

Upvotes: 1

Views: 2713

Answers (1)

Guillaume Polet
Guillaume Polet

Reputation: 47608

After changing the preferred size, you need to call revalidate() on that childPanel.

You may want to read this Oracle Tutorial on LayoutManagers

Upvotes: 4

Related Questions