my dog learned polymorphism*
The moose likes Beginning Java and the fly likes So difficult to use Layout managers!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "So difficult to use Layout managers!!!" Watch "So difficult to use Layout managers!!!" New topic
Author

So difficult to use Layout managers!!!

Alisha Burke
Greenhorn

Joined: Jan 22, 2005
Posts: 27
Why is it so difficult to use layout managers? All i want is to put all the components in the center. My button "Vote" which is suppose to be centered and just right below the textfield is now on the left side of the label.

I've been seriously contemplating to use absolute positioning but people have been telling me its a very bad idea.

I am currently using border layout and grid layout only.

Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
Get JGoodies Forms. It is so much easier than dealing with other Layout managers.
Alisha Burke
Greenhorn

Joined: Jan 22, 2005
Posts: 27
U mean i can't do it the traditional way?
Liam Tiarnach
Ranch Hand

Joined: Aug 06, 2004
Posts: 51
while, you can use other library's to make GUI design easier, you can still get the results that you want by using the standard AWT librarys...

Here, what I did was first fix the GridLayout to have just one column, second was to create a new Panel to add our button so that the button does not stretch out to fill out the bottom of the applet...

And last, since we already are adding Panel p2 to Panel p1, there is no need to add it to p3. The reason is that when p2 to p3, then adding p2 to p1, p2 get removed from p3 since it can't be two places at once...

So while a little difficult, once you get to know it, it get's easier...

I myself am still learning... but am having fun doing it...


- Liam...<br />- ' He who never sleeps... '
Alisha Burke
Greenhorn

Joined: Jan 22, 2005
Posts: 27
Hi Liam....

So how do i get the vote button to be just below the textfield/label (that was my main problem actually)....and using the code that you gave me how come the textfields becomes large when i maximize the window(is it suppose to be that way?)

thx
Liam Tiarnach
Ranch Hand

Joined: Aug 06, 2004
Posts: 51
Originally posted by Alisha Burke:
Hi Liam....

So how do i get the vote button to be just below the textfield/label (that was my main problem actually)....and using the code that you gave me how come the textfields becomes large when i maximize the window(is it suppose to be that way?)

thx


The reason is that p2 uses a GridLayout, so all components end up being the same size and also fills out each of thier cells in the grid...

As for a possible solution, you can move the button to be in the same panel as your text fields, and you can also use GridBagLayout with GridBagConstraint classes to have more control over your components in panel2... This is a very simple example, but it will give you the idea...


here is used one setting for GridBagConstraints for all components in Panel p2 which is the reason that I did not use the no-arguement constructor for GridBagConstraints...
If you desire, you can change the constraints for each individual component as necessary...

for more info on using GridBagLayout check out this link...
http://java.sun.com/docs/books/tutorial/uiswing/layout/gridbag.html

it will give more info on customizing constraints for individual components...

have fun...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: So difficult to use Layout managers!!!