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

add component to a JPanel  RSS feed

 
ajay solanki
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

I want to replace some component from a JPanel, like remove a JLabel with a JButton.

tell me any solution.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> tell me any solution.

well, there is only one solution

remove()
add()
revalidate()
repaint()//sometimes required, sometimes not, best to include always

although, depending on what you're doing, there is probably a better approach
 
ajay solanki
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Michael
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Michael Dunn:
> tell me any solution.
well, there is only one solution

Michael's recommendations are best if you have to change one to few components only. If you need to change more, or if you need to swap back and forth between states, another approach is to use a CardLayout.

You can find the Sun tutorial here
and the API here
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!