Search code examples
javaswinguser-interfacejpanelpanels

What is the purpose of Panels in java


I'm a high-school student who is taking java I usually don't have many problems that I cant figure out without a bit of research however my teacher insists all student use panels when building GUI's.I have no problem building them however I haven't been able to get a decent answer clarifying the purpose of putting components in a Panel


Solution

  • A panel is a container.

    • It allows you to group components together
    • It allows you to devise complex interfaces, as each panel can have a different layout, allowing you to leverage the power of different layout managers.
    • It allows you to build reusable components and isolate responsibility
    • But most of all, it gives you the bases for deciding how the panel should be deployed. With a panel you can add it to a frame or applet or another component as needed...
    • A panel also makes a good surface onto which to perform custom painting. For all the benefits mentioned above - its isolated and reusable...

    There are many other reasons for using panels, these are just a few that pop to mind