Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. import java.awt.*;
  2. import javax.swing.*;
  3. public class Main{
  4.     public static void main(String[] args){
  5.         JFrame fr = new JFrame("test");
  6.         MyPanel p1 = new MyPanel();
  7.         GridBagConstraints gbc = new GridBagConstraints();
  8.         gbc.insets = new Insets(5, 5, 5, 5);
  9.         gbc.fill = GridBagConstraints.HORIZONTAL;
  10.         p1.setLayout(new GridBagLayout());
  11.         gbc.gridx = 0;
  12.         gbc.gridy = 0;
  13.         p1.add(new JButton("btn1"), gbc);
  14.         gbc.gridx = 1;
  15.         gbc.gridy = 0;
  16.         p1.add(new JButton("btn1"), gbc);
  17.         gbc.gridx = 2;
  18.         gbc.gridy = 0;
  19.         p1.add(new JButton("btn1"), gbc);
  20.         gbc.gridx = 0;
  21.         gbc.gridy = 1;
  22.         gbc.gridwidth = 2;
  23.         p1.add(new JButton("btn2"), gbc);
  24.         gbc.gridwidth = 1;
  25.         gbc.gridx = 0;
  26.         gbc.gridy = 2;
  27.         p1.add(new JButton("btn3"), gbc);
  28.         fr.setContentPane(p1);
  29.         fr.setSize(500, 500);
  30.         fr.setVisible(true);
  31.         fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement