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

cannot add JComponent to JPanel  RSS feed

 
Tai Yo
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cannot add JComponent to JPanel, always getting empty. Cannot understand where is wrong. Can somebody help me?

 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JComponent doesn't have a default layout manager and has a paintComponent(...) that does nothing if the UI is null -- which it is.

To put it another way, JComponent is an abstract class provided as the superclass of all the Swing components that are intended to be used as-is. Is there a reason you don't want to use a JPanel?

Also, you are at lines 11 and 12 successively adding two components to the JFrame (which will forward the add(...) call to its contentPane) at the default location of CENTER in it's default BorderLayout. Only the last added will be managed by the BorderLayout and the first will not be visible as its bounds will be [0,0,0,0].
 
Tai Yo
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At this moment I am using JPanel to add components to JFrame, just want to know how it can be by JComponent.
Thank you very much for reply. It helped me.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!