• Post Reply Bookmark Topic Watch Topic
  • New Topic

repaint and revalidate

 
Kevin Tysen
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is part of my program. I have a JScrollPane with a JTable in it, and later the JTable gets removed. Then I have this:



The JTextArea does not become visible. I don't know why. According to part of the Java tutorial:

Problem: My component does not appear after I have added it to the container.

•You need to invoke revalidate and repaint after adding a component before it will show up in your container.


But this does not tell which object to do revalidate and repaint to. And there are several repaint methods, and this does not tell which one.
Well, I can figure out how to use repaint, I think, but I don't know which object's methods to call, the JScrollPane or the JTextArea, or maybe even the JPanel that they are in.
Oh, and also, which should go first, repaint or revalidate?
 
Darryl Burke
Bartender
Posts: 5152
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the API for JScrollPane and follow the link to the tutorial on How to Use Scroll Panes where you will find examples of the correct way to add a component to a scroll pane. (Hint: add(...) isn't it).

edit: And while your present problem has nothing to do with either revalidate() or repaint(), you would in other circumstances first revalidate, and then repaint.

And I suggest you change the subject line to suit the problem. "Adding a component to a scroll pane at run time" might be good.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!