This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Gui components alignment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Gui components alignment" Watch "Gui components alignment" New topic

Gui components alignment

Ayub ali khan
Ranch Hand

Joined: Oct 20, 2005
Posts: 380

I am using a GUI building application, here I can drag and drop the components to create a form. I need help in alignment of these components.

Each component has the following positioning attributes: Left,Top,width,Height. (in terms of %position in parent)

Suppose I have 5 labels and corresponding text fields. How can I calculate the values of Left,Top,width,Height for each component relative to the parent (canvas)?


how to align the following Form:

|First Name: -TextField----- |
|Second Name:--TextField----- |
|Address:--TextField------- |
|E-mail: --TextField------ |
|Telephone Number:--TextField----- |
| SubmitBtn |

Thanks and Best Regards


SCEA part I,TOGAF Foundation
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> how to align the following Form:

panel_2(gridLayout(1,2))//add panel_3 and panel_4 to this panel
panel_3(gridlayout(5,1))//add all labels to this panel
panel_4(gridlayout(5,1))//add all textfields to this panel
panel_5(leave as flowLayout)//add submit button to this panel
add panel_2 to panel_1(BorderLayout.CENTER)
add panel_5 to panel_1(BorderLayout.SOUTH)
Ayub ali khan
Ranch Hand

Joined: Oct 20, 2005
Posts: 380
Hi Michael,

Thank you for the info. Currently I am using a different custom application. I am not using SWING.

Thanks and Best Regards

I agree. Here's the link:
subject: Gui components alignment
Similar Threads
Problem with BoxLayout and JTextField
Using JavaScript how to pass parent form value to child
Location and bounds of a component object
How to apply styling to the Label of HTML Text component
Problem positioning Data using CSS and <s:iterate ( information is placed on top of each other).