• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why doesn't this work?  RSS feed

 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Why doesn't the second JTextField show up when I press the button? If I have the JTextField setVisible to true in the constructor, and set it to false in the actionPerformed method, it works, but if it starts out setVisible(false) it doesn't show up when the button is pressed.
I'm sure it's something really stupid, but I can't seem to find what it is...
Thanks so much for any help!
 
Jeff Smith
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add a call to validate() after the line where you set the text field visible.
Jeff
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That seems to have worked. However, I am not familiar with this method. What exactly happened here when I called this method? The API didn't really float my boat...
Thanks for the help!
 
Shashi Kanta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
whenever a container's layout needs to be reset, the invalidate() method should be called on the conatiner object.
a conatiner'r layout needs to be reset when:
1) it iself needs to be resized
2) when one or more of its components' size need to be resized
3) when a new component is going to be added
this method should be called on the components' objects (if they are involved), the conatiner and the parent container and so on upto the topmost container.
a change in layout in a child container affects the layout upto the top containment heirarchy!!
so calling invalidate() on those components or containers concerned marks them invalidate and says they need to be laid out.
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for clearing that up! Make more sense now!
 
Shashi Kanta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
u r welcome!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!