File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Revalidate problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Revalidate problems" Watch "Revalidate problems" New topic
Author

Revalidate problems

Chris Waguespack
Ranch Hand

Joined: Jul 26, 2007
Posts: 36

I have a JPanel inside of a JScrollPane that contains objects when you click the add button and deletes them when you click the delete button. Doing an add updates the screen, but a delete does not. Can anyone figure out what's going on?



Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
A very peculiar piece of programming.

Read your deleteAction method and see what it actually does. Both when there is anything in partsList, and even better when there is nothing in partsList.
Chris Waguespack
Ranch Hand

Joined: Jul 26, 2007
Posts: 36

I believe you are talking about the lack of isEmpty() checking. I know it needs to be there, just didn't add it for this simplistic example. Am I missing something else?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Originally posted by Chris Waguespack:
Am I missing something else?
Yes, I think you are.
Chris Waguespack
Ranch Hand

Joined: Jul 26, 2007
Posts: 36

Alright lets see...

First I remove the last item from the panel..
DOH!!
Ok, I need to remove the component not the index-based component.


Then I check to see if the list has any items left in it.
If it does, I modify the constraints, then remove and re-add the component with the new constraints.
When jScrollPane.revalidate() is called, the screen is not repainted.

Thanks again,
Chris
satishkumar janakiraman
Ranch Hand

Joined: May 03, 2004
Posts: 334
You should call repaint() method on JPanel.



Chris Waguespack
Ranch Hand

Joined: Jul 26, 2007
Posts: 36

Ah, thank you! That works nicely. Even after pouring over a lot of tutorials and javadocs, I still can't find the correct times to use repaint(), validate(), invalidate(), and revalidate()...does anyone know of a good resource that explains this in an easy to understand way?

Thanks a lot,
Chris

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Revalidate problems