GUI layouts and such


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: GUI layouts and such

  1. #1
    Join Date
    May 2005
    Posts
    7

    GUI layouts and such

    I'm teaching myself Java and I have come across this "exercise."
    I need to create the following GUI, but do not have to provide any
    funtionality...I cannot get the two checkboxes on the left to be as close
    together as they are supposed to be when using GridLayout or BorderLayout.
    Code:
    []Snap to grid    x:[____]     [OK]
    []Show grid       y:[____]     [Cancel]
                                           [help]
    Also, the ok, cancel, and help buttons are not aligned with anything else...any help on any of this to get me started would be appreciated...

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    If you want full control over the placement you can set the containers LayoutManager
    to null. Then call the setBounds(x,y,width,height) method for each component and
    add them to the container.

    You could have used GridBagLayout but since you are (relatively) new in java coding
    I think you should wait with that, its very nittygritty...
    eschew obfuscation

  3. #3
    Join Date
    May 2005
    Posts
    7
    I understand the placement you described, but I was wondering if you could do it with the layouts provided since your way was not covered in the book. And yes, I'm very new to Java.

  4. #4
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    The "layout" I have described can be found in other packages; Borland has a layout
    called XYLayout that is basically the same as the method I have described here. For
    that layout the constraint is called XYConstraint and that again is just a rectangle.

    My point is that (strictly speaking) the null layout w. setBounds i a form of
    layout management that doesn't stretch/compress the placements when the
    container is resized.

    You could have used a GridLayout with 3 columns and 3 rows, but then you
    would have to put two placeholders first in row 3 to get the 'help' button in column 3.
    eschew obfuscation

  5. #5
    Join Date
    May 2005
    Posts
    7
    I'm going to try the ways you mentioned...how do you put placeholders in GridLayout?...otherwise if that doesn't work I'll just use some type of coordinate layout.

  6. #6
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    I've never used it, but blank labels should do it.
    eschew obfuscation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center