Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

JFrame: Why Is A Container Necessary?

Skar.2007May 17 2024

JDK 21 | swing

Hello everyone.

If you can directly insert the Components (for example: JButton, JTextField,...) in a JFrame, why would it be necessary to previously insert a Container such as JPanel and only insert the Components on top of it?

Thank you very much already.

Comments

Omar AbdullWahhab

A kind of organizing the UI, usually you will have many controls to display to the user , if you are going to display all of these items in the JFrame only your code will become longer and unmanageable , and maintaining it will need too much efforts and time as well.

Another reason is making code reuse , for example if you are going to make and EmployeeSalaryPanel

which will display only employee salary related info, this panel can be used for the HR department's users screen , and it may also be used in another screen for the Accounting department's users.

1 - 1

Post Details

Added on May 17 2024
1 comment
134 views