Here's the code for the program I showed in the last photo post:
package jFrames; import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextField; public class Lesson29 extends JFrame { private JButton button1, button2, button3; private JTextField tf1; public static void main(String[] args) { new Lesson29(); } public Lesson29() { this.setTitle("Lesson29_GridBagLayout"); this.setSize(400, 400); this.setLocationRelativeTo(null); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); button1 = new JButton("Button1"); button2 = new JButton("Button2"); button3 = new JButton("Button3"); tf1 = new JTextField("Type here"); // SETTING THE CONTRAINTS FOR THE FIRST BUTTON gbc.gridx = 0; gbc.gridy = 0; gbc.gridheight = 1; gbc.gridwidth = 1; gbc.insets = new Insets(5,5,5,5); panel.add(button1, gbc); // SETTING THE CONSTRAINTS FOR THE SECOND BUTTON gbc.gridy++; panel.add(button2, gbc); // SETTING THE CONSTRAINTS FOR THE TEXTFIELD gbc.gridy--; gbc.gridx++; gbc.fill =GridBagConstraints.HORIZONTAL; panel.add(tf1, gbc); // SETTING THE CONSTRAINTS FOR THE THIRD BUTTON gbc.gridy++; gbc.fill = 0; panel.add(button3, gbc); // CREATING A FONT TO SET ON THE TEXT FIELD tf1.setHorizontalAlignment(JTextField.CENTER); Font newFont = new Font("play", Font.PLAIN, 12); tf1.setFont(newFont); panel.setBorder(BorderFactory.createTitledBorder("Panel1")); this.add(panel); this.setVisible(true); } }



















