Results 1 to 5 of 5
  1. #1
    tiptoe is offline Member
    Join Date
    Jan 2010
    Posts
    3
    Rep Power
    0

    Question Alignment using BoxLayout

    Hi all,

    I have been recently experimenting with the "setAlignmentX()" and "setAlignmentY()" methods within the context of a BoxLayout, and all appeared well until I began adding "Box.createRigidArea(..)" components.

    As the rigid area return type is "Component" as opposed to "JComponent", I am unable to invoke the above methods in order to retain a consistent alignment strategy within the parent container.

    Does anyone know a way in which I can set the appropriate alignments of the objects returned by "Box.createRigidArea(..)"?

    Best regards, Gemma.

  2. #2
    zweibieren is offline Senior Member
    Join Date
    Aug 2009
    Location
    Pittsburgh, PA
    Posts
    284
    Rep Power
    6

    Default

    Checking the Box.java code, we can see that Box.createRigidArea(...)
    returns an object which is in fact a JComponent.
    So a rigid area with an alignment can be created with
    Java Code:
    JComponent rigidArea = (JComponent)Box.createRigidArea(...);
    rigidArea.setAlignmentX(...);

  3. #3
    tiptoe is offline Member
    Join Date
    Jan 2010
    Posts
    3
    Rep Power
    0

    Default

    So simple, yet utterly brilliant!!!

    Being neither confident nor competent enough to trawl through JDK source code, I would like to thank you for your time in securing the information that has eluded me for several days.

    Again, thank you for allowing me to put this issue to bed and move on to my next assignment.

    All the best, Gemma xxx

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

    Default

    Don't forget to "rep" him for his helpful advice. ;)

  5. #5
    tiptoe is offline Member
    Join Date
    Jan 2010
    Posts
    3
    Rep Power
    0

    Default

    Ah, OK; I hadn't realised that this facility was available :)

    Have just left "zweibieren" the appropriate rep.

    Thanks for the heads up :)

    Gemma xxx

Similar Threads

  1. BoxLayout problems
    By paulb in forum New To Java
    Replies: 2
    Last Post: 11-04-2009, 11:04 PM
  2. BoxLayout Behaviour
    By PetalumaBoy in forum AWT / Swing
    Replies: 4
    Last Post: 06-10-2009, 02:27 PM
  3. Replies: 7
    Last Post: 05-22-2009, 04:57 AM
  4. Replies: 4
    Last Post: 02-16-2009, 10:52 PM
  5. Label Alignment Example
    By Java Tip in forum javax.swing
    Replies: 0
    Last Post: 06-27-2008, 08:49 PM

Posting Permissions

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