JFrame pack()

The pack method packs the components within the window based on the component’s preferred sizes.

Program

1

 

 

 

Program Source

import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.FlowLayout;

class Frame extends JFrame {
   
    void makeSizedFrame()
    {
        setTitle("SetSize(700,200)");
        setLayout(new FlowLayout());
        setButton();
        setSize(700, 200);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    
    void makepackFrame()
    {
        setTitle("Withpack()");
        setLayout(new FlowLayout());
        setButton();
        pack();
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    
    void setButton()
    {
        for(int i=0; i

Leave a Comment