This section provides you an example which illustrates you about the main difference between the pack() method and the setSize() method of the Java Swing.
Here, you can see the given example provides a JFrame with some button component like Button 1, Button 2, Button3, Button 4, Button 5 etc. on it. The frame is seen by using the pack() method. If you do not use the pack method frame is not resized and only the title of the frame will bee seen. To show everything on the frame, frame will be resized by the pack() method or the setSize() method of Java Swing.
The main difference between the pack() method and setSize() method of Java Swing is as follows:
pack() method gives sets the frame size as per need while the setSize() method takes two parameter in which one is for the width of the frame and another one is for the height of the frame to represent it.
Here is the code of the program
import java.awt.*;
|
Output of the above example:

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: pack() vs. setSize() Method in Java View All Comments
Post your Comment