Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

contentPane  RSS feed

 
saravanan ragunathan
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the differnce between adding "JPanel to "contentpane(JFrame) and adding "JPanel as" contentpane...which one is perfect for what



 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you create a new instance of a JFrame the constructor creates a root pane, which in turn creates the content pane, which is a JPanel.
This JPanel is assigned some properties that make it suitable for use as a content pane.
It's opaque (by default), and it's assigned a BorderLayout layout manager - overriding the default FlowLayout.

Explicitly setting the content pane allows you to change these default properties, or indeed use a JComponent sub-type other than JPanel.
In your example the difference would be that your content pane would use the FlowLayout layout manager instead of the defaut BorderLayout.
 
Campbell Ritchie
Sheriff
Posts: 53742
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to JavaRanch
 
saravanan ragunathan
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your explanation

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!