Which layout manager for this case?

Discussion in 'Java' started by Rene Ruppert, Sep 6, 2004.

  1. Rene Ruppert

    Rene Ruppert Guest

    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é
     
    Rene Ruppert, Sep 6, 2004
    #1
    1. Advertisements

  2. Rene Ruppert

    Paul Lutus Guest

    Example, please. GridBagLayout can do what you want, but you have to learn
    how to use it.
     
    Paul Lutus, Sep 6, 2004
    #2
    1. Advertisements

  3. Rene Ruppert

    Rene Ruppert Guest

    Hi Paul,
    I solved it using a simple FlowLayout. :)

    Thanks.

    cu

    René
     
    Rene Ruppert, Sep 8, 2004
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.