java pr4
java pr4
*;
import javax.swing.*;
public GridBagLayoutExample() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel.setLayout(new GridBagLayout());
gbc.gridx = 0;
gbc.gridy = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.gridx = 1;
gbc.gridy = 0;
gbc.gridx = 2;
gbc.gridy = 0;
gbc.gridx = 0;
gbc.gridy = 1;
gbc.gridwidth = 3;
gbc.gridy = 2;
gbc.gridwidth = 3;
add(panel);
pack();
setLocationRelativeTo(null);
setVisible(true);
new GridBagLayoutExample();
OUTPUT:
import javax.swing.*;
import java.awt.*;
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gbc.gridx = 0;
gbc.gridy = 0;
gbc.anchor = GridBagConstraints.WEST;
gbc.gridx = 1;
gbc.gridy = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.gridx = 0;
gbc.gridy = 1;
gbc.anchor = GridBagConstraints.WEST;
gbc.gridx = 1;
gbc.gridy = 1;
gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
// Submit button
gbc.gridx = 1;
gbc.gridy = 2;
gbc.anchor = GridBagConstraints.EAST;
gbc.fill = GridBagConstraints.NONE;
gbc.weightx = 0.0;
gbc.weighty = 0.0;
frame.add(panel);
frame.pack();
frame.setVisible(true);