The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

how to position gui components

hello everybody i have been learning java for the summer for next semester i am currently looking at gui i was wondering how you can position components such as JLabels and JTextFields where ever you want. here is a peice of code i have been working on

i know about flowlayout and i have hearded about gridlayout. but when i run this program both labels and textfields are in the top and center. what i want to do is position the first textfield and label in the bottom left hand corner and the second label and textfield in the top right hand corner. i know i sounds weird but i just need an example like that so i can understand how to do it.

Re: how to position gui components

setHorizontalTextPosition and setVerticalTextPosition refer to the position of the text within the text component, not where the component displays.

I find BorderLayout most convenient for placing components top, bottom, left, or right because the centre part of BorderLayout expands to take up all available space. Generally, the simplest way to use layouts is to combine them, nesting layouts within panels. In this case, I'd have a top (North) panel and a bottom (South) panel and use a BorderLayout within each to place the components to the right (East) and left (West) respectively. To make the label and text fields sit next to each other, I'd put them into their own sub-panels: