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.
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...
Snap to grid x:[____] [OK]
Show grid y:[____] [Cancel]
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...
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.
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.
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.
I've never used it, but blank labels should do it.
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL