Discussion:
Newbie: Prevent stretching of widgets when using LayoutManagers?
(too old to reply)
f***@hotmail.com
19 years ago
Permalink
Hi all,

The problem with my Java components is that they stretch along when I
resize the window. They become way too big.

I've been able to prevent this using:

thePanel.setMinimumSize( thePanel.getPreferredSize() );
thePanel.setMaximumSize( thePanel.getPreferredSize() );

But once I started using JTabbedPane inside another JTabbedPane this
method does not seem to work anymore.

Can anyone help?
Any help or hint will be greatly appreciated!

Best regards,
Francis
Monique Y. Mudama
19 years ago
Permalink
Post by f***@hotmail.com
Hi all,
The problem with my Java components is that they stretch along when
I resize the window. They become way too big.
thePanel.setMinimumSize( thePanel.getPreferredSize() );
thePanel.setMaximumSize( thePanel.getPreferredSize() );
But once I started using JTabbedPane inside another JTabbedPane this
method does not seem to work anymore.
Can anyone help? Any help or hint will be greatly appreciated!
I can't give you the answer, but I think that the answer will depend
on which LayoutManager each of your panels is using. Different
LayoutManagers respect different size constraints.

What layout managers are you using?

You can probably address the sizing issues by using a different layout
manager.
--
monique

Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
f***@hotmail.com
19 years ago
Permalink
Hoping this won't be too complex:

- the top JFrame contains one JTabbedPane, no explicit layoutmanager
defined
- all the tabs themselves have no explicit layoutmanager defined
- the second tab contains another JTabbedPane, no explicit
layoutmanagers defined
- the second tab of the second tab is the problematic pane. It has
following layoutmanager:
setLayout( new BoxLayout( this, BoxLayout.Y_AXIS ) );

Does this help?
Monique Y. Mudama
19 years ago
Permalink
Post by f***@hotmail.com
- the top JFrame contains one JTabbedPane, no explicit layoutmanager
defined - all the tabs themselves have no explicit layoutmanager
defined - the second tab contains another JTabbedPane, no explicit
layoutmanagers defined - the second tab of the second tab is the
problematic pane. It has following layoutmanager: setLayout( new
BoxLayout( this, BoxLayout.Y_AXIS ) );
Does this help?
It would have helped more if you'd included the original problem
description =P

Anyway, I do seem to recall running into situations where a vertical
BoxLayout will eat up all the horizontal space it can get. I'm not
sure, but you might try putting the BoxLayout panel *inside* a panel
that has a BorderLayout, and add the BoxLayout panel to the WEST.
This should (if I'm remember everything correctly) put the BoxLayout
panel on the far left of the window and respect the preferred size.
--
monique

Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
f***@hotmail.com
19 years ago
Permalink
Wrapping the pane into another JPanel fixed my problem.
Biswa Prakash
19 years ago
Permalink
Hi,
You can do a simple thing.
Set the dimension of the panels as
thePanel.setPreferredSize( new Dimension(x,y) );
where x and y are integer values that define width and height of your
panel.
This is going to solve your purpose.
Prakash
Post by f***@hotmail.com
Hi all,
The problem with my Java components is that they stretch along when I
resize the window. They become way too big.
thePanel.setMinimumSize( thePanel.getPreferredSize() );
thePanel.setMaximumSize( thePanel.getPreferredSize() );
But once I started using JTabbedPane inside another JTabbedPane this
method does not seem to work anymore.
Can anyone help?
Any help or hint will be greatly appreciated!
Best regards,
Francis
Loading...