0
package pkg1;

import java.awt.*;
import javax.swing.*;

public class Main {

    public static void main(String[] args) {


        JFrame frm = new JFrame("Title");
        JTextField txt = new JTextField();
        JLabel lbl = new JLabel("To");
        JTextField txt2 = new JTextField();


        frm.setLayout(new GridLayout(2,2,5,5));
        frm.add(txt);
        frm.add(lbl);      
        frm.add(txt2);      

        frm.setSize(500,100);
        frm.setVisible(true);
        frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frm.setLocationRelativeTo(null);

    }
}

Someone please explaine to me how to change the location on my txt2 to be aligned w/ my txt1.
I habe been searching the net for hours but the solutions they show seems to have no effect?

2
Contributors
1
Reply
10
Views
3 Years
Discussion Span
Last Post by stultuske
1

what do you mean: aligned? they are aligned.
if you want them next to each other, instead of underneath, you'll need to change the values of the rows and columns in the constructor for the GridLayout.

now you set:

new GridLayout(2,2,5,5)
try with:
new GridLayout(1,3,5,5)
you have searched the net for hours, but what is it you tried so far?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.