import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.GridLayout;
public class ShowGridLayout extends JFrame {
public ShowGridLayout() {
// Set GridLayout, 3 rows, 2 columns, and gaps 5 between
// components horizontal and vertically
setLayout(new GridLayout(3, 2, 5, 5));
// Add lables and text fields to the frame
add(new JLabel("First Name"));
add(new JTextField(8));
add(new JLabel("Mi"));
add(new JTextField(1));
add(new JLabel("Last Name"));
add(new JTextField(8));
}
/* Main method */
public static void main(String[] args) {
ShowGridLayout frame = new ShowGridLayout();
frame.setTitle("ShowGridLayout");
frame.setSize(200,125);
frame.setLocationRelativeTo(null); // Center the frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.GridLayout;
public class ShowGridLayout extends JFrame {
public ShowGridLayout() {
// Set GridLayout, 3 rows, 2 columns, and gaps 5 between
// components horizontal and vertically
setLayout(new GridLayout(3, 2, 5, 5));
// Add lables and text fields to the frame
add(new JLabel("First Name"));
add(new JTextField(8));
add(new JLabel("Mi"));
add(new JTextField(1));
add(new JLabel("Last Name"));
add(new JTextField(8));
}
/* Main method */
public static void main(String[] args) {
ShowGridLayout frame = new ShowGridLayout();
frame.setTitle("ShowGridLayout");
frame.setSize(200,125);
frame.setLocationRelativeTo(null); // Center the frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}