AndreaNobili
AndreaNobili

Reputation: 43047

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

Upvotes: 1

Views: 307

Answers (4)

santu
santu

Reputation: 685

  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.

Upvotes: 2

Som
Som

Reputation: 864

  • Basically, a JFrame represents a framed window and a JPanel represents some area in which controls (e.g., buttons, checkboxes, and textfields) and visuals (e.g., 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.

Upvotes: 1

Hemant Metalia
Hemant Metalia

Reputation: 30678

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

Upvotes: 5

Matteo Gatto
Matteo Gatto

Reputation: 626

A JFrame rappresent a window, the jpanel is a part of the gui contained in a window.

http://docs.oracle.com/javase/tutorial/uiswing/components/frame.html

http://docs.oracle.com/javase/tutorial/uiswing/components/panel.html

Upvotes: 3

Related Questions