Results 1 to 5 of 5
  1. #1
    random7 is offline Member
    Join Date
    Jul 2010
    Posts
    11
    Rep Power
    0

    Default group layout - link the size of components in different labels ?

    Hi,

    i have a gui in which has 5 panels (layed out from top to bottom in one column, using grouplayout).

    now inside each of the panels it looks like this (they use grouplayout as well):
    Java Code:
    label 1		component
    labelexample 2	component

    however, the labels arent always the same size, e.g. the labels in panel 3 are 50% longer than the ones in panel 5
    so all in all it looks like this:
    Java Code:
    panel 1
    ----------------------------------------------------------
    label 1       	component
    labelexample 2 	component
    ----------------------------------------------------------
     
    panel 2
    ----------------------------------------------------------
    label 1				component
    labelexample_takesmorespace 2 	component
    ----------------------------------------------------------
    
    panel 3
    ----------------------------------------------------------
    label 1 component
    label 2 component
    ----------------------------------------------------------
    
    ...
    ...

    I'd really like all the labels be the same size, so that the components all start at the same line. ive tried layout.linksize in the main frame, but this doesnt work, since the jlabels arent in a group in the main frame layout :( ( --> an exception is being thrown)

    is there a way to do this? Any help apprechiated :)

  2. #2
    Prajin's Avatar
    Prajin is offline Senior Member
    Join Date
    Jun 2010
    Location
    Ktm, Nepal
    Posts
    120
    Rep Power
    0

    Default

    Define the size of one component in each panel and link it's size with others in same panel.
    What I mean is :
    Java Code:
    for panel1
    label1.setSize(x,y);
    // then link with others of panel1.
    
    
    for panel2
    label2.setSize(x,y);
    // then link with others of panel2.
    That may work.

    -regards
    Last edited by Prajin; 08-04-2010 at 01:43 PM.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

  4. #4
    random7 is offline Member
    Join Date
    Jul 2010
    Posts
    11
    Rep Power
    0

    Default

    Quote Originally Posted by prajin
    Define the size of one component in each panel and link it's size with others in same panel.
    What I mean is
    ...
    Thanks for your reply. Im going to try that. But this solution requires me to know the length of the longest label in use, right? Is there a way to guess that length already before the initiation of the gui components?

  5. #5
    random7 is offline Member
    Join Date
    Jul 2010
    Posts
    11
    Rep Power
    0

    Default

    Ok, i got it now. Almost the way you suggested, prajin.


    Here's how to do it:
    Define a variable for the size of the longest label
    Java Code:
    private Dimension labelSize = new Dimension(x,y);

    Then for each panel:
    Setting the minimum size of one of the labels used in that panel is enough
    Java Code:
    JLabel label1 = new JLabel("content");
    label1.setMinimumSize(labelSize);
    JLabel label2 = ....
    JLabel ...
    ...
    You dont have to use layout.linkSize. This would actually revert the effect and all labels will become "normal" again, if you have labels that are smaller than the "labelSize" dimension

    This way works fine, even though you have to know the size of the longest variable.



    // im sorry for the crosspost, but i waited more than 2 weeks (in the other forum) and no one would help me, so i finally postet the question here as well. ill update the other thread as well.

Similar Threads

  1. group layout - span ?
    By random7 in forum AWT / Swing
    Replies: 4
    Last Post: 07-26-2010, 09:26 AM
  2. Help needed in layout of components
    By silversurfer2in in forum AWT / Swing
    Replies: 2
    Last Post: 05-27-2010, 11:50 AM
  3. Components Layout in a JPanel
    By jboy in forum New To Java
    Replies: 4
    Last Post: 10-11-2009, 12:08 PM
  4. size och swt labels
    By larsk in forum SWT / JFace
    Replies: 0
    Last Post: 10-04-2009, 12:01 PM
  5. Layout problem / add components from another class
    By ehochedez in forum AWT / Swing
    Replies: 9
    Last Post: 09-02-2009, 10:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •