Which layout manager for this case?

R

Rene Ruppert

Hi,

I've tried all layout managers so far and no one did what I wanted it to. I
know GridBagLayout will do the job but I cannot figure out how to use it.

I want to have several components width different heights (!) to be aligned
vertically or horizontally.

If I use the following code the components get resized in height (thouh
printing getSize() and getPreferredSize() shows that there height hasn't
changed):

GridBagLayoutgbc.anchor = GridBagConstraints.NORTH;
gbc.gridx = 0;
gbc.gridy = GridBagConstraints.RELATIVE;
gbc.fill = GridBagConstraints.NONE;
parentComponent.add(this, gbc);

If I use the code everything is fine and the components get aligned
horizontally width correct widths and heights:

GridBagLayoutgbc.anchor = GridBagConstraints.WEST;
gbc.gridx = GridBagConstraints.RELATIVE;
gbc.gridy = 0;
gbc.fill = GridBagConstraints.NONE;
parentComponent.add(this, gbc);

Can anybody help please!?

Thanks.

cu

René
 
P

Paul Lutus

Rene said:
Hi,

I've tried all layout managers so far and no one did what I wanted it to.
I know GridBagLayout will do the job but I cannot figure out how to use
it.

I want to have several components width different heights (!) to be
aligned vertically or horizontally.

Example, please. GridBagLayout can do what you want, but you have to learn
how to use it.
 
R

Rene Ruppert

Hi Paul,
Example, please. GridBagLayout can do what you want, but you have to learn
how to use it.

I solved it using a simple FlowLayout. :)

Thanks.

cu

René
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top