[Java] The difference and usage of JPanel and JFrame

Summary:
Jpanel needs to be attached to JFrame to exist, you can directly add other components
and JFrame can exist alone, but you need to add other components through the content pane

JFrame
itself has a menu bar.
Adding components is first added to the content pane through the add method and then placed in the frame

The content pane is a transparent middle container with no border.

Function member effect
setDefaultLookAndFeelDecorated (booleandefaultLookAndFeelDecorated) Set the Windows appearance used by the JFrame window (such as borders, widgets that close the window, titles, etc.)
getDefaultCloseOperation() Returns the operation performed when the user clicks the "Close" button on this form (set to JFrame to close)

The
middle level of JPanel should be placed under other components, and at the same time can accommodate components and combine them
. The default layout manager at creation is FlowLayout, which can be specified

Refer

Published 70 original articles · Likes0 · Visits 1705

Guess you like

Origin blog.csdn.net/weixin_44807751/article/details/103794925