Java JButton set preferred size

Description

Java JButton set preferred size

import java.awt.Dimension;
import java.awt.FlowLayout;

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

public class Main extends JFrame {
  public Main() {
    super("JButton");

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setLayout(new FlowLayout());

    /*from  w w w.  ja v  a2  s.  c  o m*/
    JButton bn = new JButton("Close");
    bn.setPreferredSize(new Dimension(100, 60));

    getContentPane().add(bn);
  }

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



PreviousNext

Related