GridBagConstraints.gridy
//gridx
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class MainClass extends JPanel {
GridBagConstraints constraints = new GridBagConstraints();
public MainClass() {
setLayout(new GridBagLayout());
int x, y; // for clarity
addGB(new JButton("North"), x = 1, y = 0);
addGB(new JButton("West"), x = 0, y = 1);
addGB(new JButton("Center"), x = 1, y = 1);
addGB(new JButton("East"), x = 2, y = 1);
addGB(new JButton("South"), x = 1, y = 2);
}
void addGB(Component component, int x, int y) {
constraints.gridx = x;
constraints.gridy = y;
add(component, constraints);
}
public static void main(String[] args) {
JFrame frame = new JFrame("GridBag1");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(225, 150);
frame.setLocation(200, 200);
frame.setContentPane(new MainClass());
frame.setVisible(true);
}
}
Related examples in the same category
1. | GridBagConstraints.BOTH | | |
2. | GridBagConstraints.CENTER | | |
3. | GridBagConstraints.NONE | | |
4. | GridBagConstraints.RELATIVE | | |
5. | new GridBagConstraints() | | |
6. | new GridBagConstraints(int gx, int gy, int gw, int gh, double wx, double wy, int a, int f, Insets i, int ipx, int ipy) | | |
7. | GridBagConstraints.fill | | |
8. | GridBagConstraints.gridheight | | |
9. | GridBagConstraints.gridwidth | | |
10. | GridBagConstraints.gridx | | |
11. | GridBagConstraints.ipadx | | |
12. | GridBagConstraints.ipady | | |
13. | GridBagConstraints.weightx | | |
14. | GridBagConstraints.weighty | | |