简体   繁体   中英

Difference from JFrame and JPanel object int Java Swing?

I know that JFrame is a top level container fro Swing GUI and that I can put a JPanel object inside a JFrame object.

But also JPanel is a container...so what is the difference from JFrame and JPanel.

I see that, in the GUI implementation, is implement directly a JPanel object, other times I see that is implemented a JFrame in which I put a JPanel.

What is the difference?

Tnx

Andrea

JFrame - Used to represent the features a like a window. This includes border,titlebar, different controls, and different event handlers. refer : http://docs.oracle.com/javase/6/docs/api/javax/swing/JFrame.html

JPanel - Most Generic class used as a container to gather other elements together. This is more important with working with the visual layout or one of the provided layout managers. refer : http://docs.oracle.com/javase/6/docs/api/javax/swing/JPanel.html

EDIT: Some more

  1. JPanel serves as a general purpose container, while JFrame is a window commonly used for stand-alone applications, like a warning window, or a notification window.
  2. JPanel represents an area used for more complex operations or applications.
  3. In JPanel, one panel can hold many operations, while in JFrame, it can have inner frames for a different purpose. Read more: Difference Between JPanel and JFrame | Difference Between | JPanel vs JFrame http://www.differencebetween.net/technology/difference-between-jpanel-and-jframe/#ixzz2g0DDAgAq
  1. The similarity is both are containers.
  2. JFrame is a contrainer which can hold JPanel.
  3. The best use when I had used long days back, when I inherit JPanel instead JFrame, so latter on, the component can be used in both JFrame and JApplet.
  4. You can add multiple JPanels inside a JFrame. You can set the different layouts.
  • Basically, a JFrame represents a framed window and a JPanel represents some area in which controls (eg, buttons, checkboxes, and textfields) and visuals (eg, figures, pictures, and even text) can appear.

  • JPanel serves as a general purpose container, while JFrame is a window commonly used for stand-alone applications, like a warning window, or a notification window.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM