Java JFrame set FlowLayout to content pane

Description

Java JFrame set FlowLayout to content pane

import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JFrame;

public class Main extends JFrame {

  public Main() {
    super("demo from demo2s.com");
    JButton closeButton = new JButton("Close");
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    setLayout(new FlowLayout());

    getContentPane().add(closeButton);// w  ww .j  a v a  2s. c om

    closeButton.addActionListener(e -> System.exit(0));
  }

  public static void main(String[] args) {
    Main frame = new Main();
    frame.pack();
    frame.setVisible(true);
  }
}



PreviousNext

Related