Results 1 to 8 of 8
  1. #1
    Hades82 is offline Member
    Join Date
    Dec 2010
    Posts
    3
    Rep Power
    0

    Question Group Layout Alignment

    Hello,

    Here is the problem: I have a variable number of components positioned as I want in a GroupLayout (the layout and position between components work as I want). I add this GroupLayout to a JPanel and this one to a JFrame, and I see that the group is aligned to the up-left corner.

    The question is, how do I get the group centered in the JPanel? I mean I want to see the GroupLayout centered in the maximized JFrame in both horizontal and vertical axis.

    I supose that the answer to my question is so easy but I cannot see it.
    Thank you for your anwers!!

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

    Default

    pack() the frame and you won't have extra space.

    db

  3. #3
    Hades82 is offline Member
    Join Date
    Dec 2010
    Posts
    3
    Rep Power
    0

    Default

    yes, it was my first solution but since the number of components is variable the frame becomes resized continously, and it's unconfortable to use. I would like to do the same but with the frame maximized, if it's possible, controlling the position of the whole group in the frame.
    Thank you for your answer!!

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    As your question gains more requirements and becomes more complex, the solution becomes more difficult. I suggest you create an SSCCE to show us a demo of the problem and to allow us to test and modify running code. Please read the link, because yes we want compilable and runnable code, but no, we don't want to see you're whole program.

    Much luck!

  5. #5
    fex
    fex is offline Member
    Join Date
    Dec 2010
    Posts
    20
    Rep Power
    0

    Default

    I would create my own LayoutManager instead of one of the defaults. Simply override the 5 methods as declared in the API. (Java Platform SE 6)

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

    Default

    I want to see the GroupLayout centered in the maximized JFrame in both horizontal and vertical axis.
    For these exact requirements I would lay out my components ins a JPanel and add that to a container -- the JFrame's contentPane, probably -- with a GridBagLayout and no constraint.

    db

  7. #7
    aephyr is offline Member
    Join Date
    Nov 2010
    Posts
    4
    Rep Power
    0

    Default

    Use a ParallelGroup with the alignment of ... GroupLayout.Alignment.CENTER.

    If you are using the no-arg constructor, it defaults to LEADING, which is left/top for horizontal/vertical.

    If you are using SequentialGroup for either of your axes, simply add that group to the centered ParallelGroup.

  8. #8
    Hades82 is offline Member
    Join Date
    Dec 2010
    Posts
    3
    Rep Power
    0

    Default

    Hi all,
    Sorry for not anwering before. Finally I tried a solution with a GridBagLayout in my frame, as Darryl.Burke said, keeping my Jpanel with a GroupLayout. It works!!
    Thank you for your help. I would like to post an image with a first aproach of my work but I don't know if it's possible in this forum
    Anyway, thank you again!!

Similar Threads

  1. Replies: 4
    Last Post: 08-05-2010, 08:08 AM
  2. group layout - span ?
    By random7 in forum AWT / Swing
    Replies: 4
    Last Post: 07-26-2010, 09:26 AM
  3. Help with alignment
    By firecat318 in forum AWT / Swing
    Replies: 3
    Last Post: 05-25-2010, 03:01 AM
  4. Edit layout Layout please help me
    By manhtungtnk28@gmail.com in forum New To Java
    Replies: 4
    Last Post: 11-23-2009, 08:41 AM
  5. what layout to use for vertical alignment?
    By dim_ath in forum AWT / Swing
    Replies: 6
    Last Post: 01-20-2008, 05:28 PM

Tags for this Thread

Posting Permissions

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