This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

placing swing components

 
cinderalla rahul
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends,
I have a problem in placing a components.
I have a JPanel whose background is set by backgroundpanel(backgroundpanel is JPanel in which the image is painted(using graphics)).
So JPanel's background image is set like this.
Now i am adding swing components(JButton,JTextField..) over this JPanel.
JPanel.add(Backgroundpanel);
backgroundpanel.add(jtextfield1);
....
But these swing components are not visible.But if these components are AWT components then its visible.
How come be overcome.
Light weight component(JButton,JTextField..) is being placed over the lightweightcomponent(JPanel).
Then why is not possible.I need Swing components to be placed.
Excepting ur replies,
with regards,
cinderallarahul.
 
Rashid Ali
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems that you are missing getContentPane() method that's why they are visible in AWT but not Swing cuz Swing requires this method to add component in the GUI.
As you are adding your components to JPanel instance. And now what you have to do is to add your JPanel instance with the getContentPane().
Try out the following example:

that's it. Note that getContentPane() is not required by AWT components but Swing does.
Hope it clarifies.
Good luck
Rashid Ali
[ January 21, 2002: Message edited by: Rashid Ali ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic