• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

So difficult to use Layout managers!!!

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Get JGoodies Forms. It is so much easier than dealing with other Layout managers.
 
Alisha Burke
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
U mean i can't do it the traditional way?
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Alisha Burke
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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...
reply
    Bookmark Topic Watch Topic
  • New Topic