The difference between JFrame and JPanel

Although both JPanel and JFrame are commonly used components in the java.swing package, the difference between them is still very big.

JPanel is a lightweight container that needs to be placed in the top-level container before it can be displayed, such as JFrame, JDialog, JWindow, etc.

JFrame is the top-level container that can hold components such as JPanel

JPanel can nest JPanel, but cannot place top-level containers such as JFrame in JFrame

JPanel defaults to flow layout FlowLayout, JFrame defaults to border layout BorderLayout

The default version of JPanel display status is true, JFrame needs to call setVisable(true); method to display

JFrame has the border of the window, with a title bar, a border maximize button, a minimize button, and a close button. JPanel has no borders by default and does not have these buttons

Guess you like

Origin blog.csdn.net/weixin_45729934/article/details/106127876