• Post Reply Bookmark Topic Watch Topic
  • New Topic

Newb question - repainting dynamically added Checkbox  RSS feed

 
Matthew Cox
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When the item is added it is not visible within the container until I resize the container. I tried calling repaint() on both the added component and the container but still doesn't update the visibility.

I am rusty with swing right now.
I know this is something silly, can anyone point me in the right direction?

Thanks
 
Campbell Ritchie
Sheriff
Posts: 55351
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I shall move you to the Swing forum, but: have you set a size for your frame? Are you setting the frame visible before adding all the components? If you do that, try calling revalidate() on it right at the end of your method/constructor.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:If you do that, try calling revalidate() on it right at the end of your method/constructor.


In addition to what Campbell said, sometimes it is required to call repaint too. So, in general, always call revalidate() and repaint() and you can live happily ever after
 
Matthew Cox
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answer to my own question. revalidate() was on the right track ... I knew it was a method similar in appearance to this one.

The class Container has a validate() method which forcing the container to lay its elements on the screen again.

1.5 API

public void validate()Validates this container and all of its subcomponents.
The validate method is used to cause a container to lay out its subcomponents again. It should be invoked when this container's subcomponents are modified (added to or removed from the container, or layout-related information changed) after the container has been displayed.


Overrides:
validate in class Component
See Also:
add(java.awt.Component), Component.invalidate(), JComponent.revalidate()





So I simply called validate() after dynamically modifying th component
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!