fubarable

Layout example

Oct 7th, 2022
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. import java.awt.*;
  2. import javax.swing.*;
  3.  
  4. public class Example2 {
  5.  
  6.     public static void main(String[] args) {
  7.         SwingUtilities.invokeLater(() -> {
  8.            
  9.             JLabel label = new JLabel("Click the button!");
  10.            
  11.             JPanel labelPanel = new JPanel();
  12.             labelPanel.add(label);
  13.            
  14.             JButton bt = new JButton("Click me");
  15.             bt.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 64));
  16.            
  17.             JPanel centerPanel = new JPanel();
  18.             int eb = 20;
  19.             centerPanel.setBorder(BorderFactory.createEmptyBorder(eb, eb, eb, eb));
  20.             centerPanel.add(bt);
  21.            
  22.  
  23.             JPanel mainPanel = new JPanel(new BorderLayout());
  24.             mainPanel.add(labelPanel, BorderLayout.PAGE_START);
  25.             mainPanel.add(centerPanel, BorderLayout.CENTER);
  26.            
  27.             JFrame frame = new JFrame("GUI");
  28.             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  29.             frame.add(mainPanel);
  30.             frame.pack();
  31.             frame.setLocationRelativeTo(null);
  32.             frame.setVisible(true);
  33.         });
  34.     }
  35.  
  36.        
  37. }
Add Comment
Please, Sign In to add comment