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
import java.awt.FlowLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.SwingConstants; public class gui extends JFrame{ private JTextField num1; private JTextField num2; //private JTextField num3; private JLabel lnum1; private JLabel lnum2; //private JLabel lnum3; public gui(){ super("sum program"); setLayout(new FlowLayout()); lnum1 = new JLabel("first number"); lnum1.setToolTipText("enter the first number here."); num1 = new JTextField(10); lnum1.setHorizontalTextPosition(SwingConstants.LEFT); lnum1.setVerticalTextPosition(SwingConstants.BOTTOM); lnum2 = new JLabel("second number"); lnum2.setToolTipText("enter the second number here."); lnum2.setHorizontalTextPosition(SwingConstants.RIGHT); lnum2.setVerticalTextPosition(SwingConstants.TOP); num2 = new JTextField(10); add(lnum1); add(num1); add(lnum2); add(num2); } }
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.
thanks in advance.