wood burning stoves*
The moose likes Swing / AWT / SWT and the fly likes Problem clearing my ArrayList, a ghost is filling it up again. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem clearing my ArrayList, a ghost is filling it up again." Watch "Problem clearing my ArrayList, a ghost is filling it up again." New topic
Author

Problem clearing my ArrayList, a ghost is filling it up again.

Alexander Selling
Greenhorn

Joined: Apr 27, 2010
Posts: 16
Hi!

So the purpose of this program is to display the correct children to the parent you click on, for instance if you click on "room" you should get a couple of children named "wall", "floor", "ceiling" and so on..
What I want is, when you click on room all the other options that were available should disappear and only the children of chosen object should appear.
Now I've almost got it all to work, except for the ArrayList of strings called "strn".

First you click on a checkbox, getQuery is called and returns the children of that checkbox. Now the arraylist strn is filled with these children
and is sent off to the method called generateMenu, the checkboxes are generated. Up til this point everything is fine, however the next time this happens it generates the old and the new checkboxes, in other words the parents and the children into a big mess. I've tried to create a new arraylist, I've tried to use strn.clear(), I've tried to use strn.removeAll(strn). But it still somehow remembers what the old objects are ?

It's so weird to look at my little test code:

System.out.println(strn.toString());
strn.removeAll(strn);
System.out.println(strn.toString());
The first print line gives a full array and the 2nd gives an empty one, so it is empty ? But somehow it stores them and remembers to put them back in there when the method is called the next time.
And btw I've had all sorts of diff ways to clear/remove the array this is just one of them.


Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

What about the returned value of getQuery ? Is it ok ? Isn't getQuery returning you too many results ?


[My Blog]
All roads lead to JavaRanch
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

updateUI() isn't the correct method to invoke after adding/removing components from a visible container. Use revalidate() and repaint() instead.


luck, db
There are no new questions, but there may be new answers.
Alexander Selling
Greenhorn

Joined: Apr 27, 2010
Posts: 16
Christophe Verré wrote:What about the returned value of getQuery ? Is it ok ? Isn't getQuery returning you too many results ?


Thanks a bunch, I never cleared the arraylist that the class Query fills the "queries" with. Now it's all working.

Darryl Burke wrote:updateUI() isn't the correct method to invoke after adding/removing components from a visible container. Use revalidate() and repaint() instead.


I've changed now, but what is the difference ?
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Read the documentation for updateUI()
Notification from the UIManager that the L&F has changed.

And for revalidate()
Supports deferred automatic layout.

Which looks appropriate to you?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem clearing my ArrayList, a ghost is filling it up again.
 
Similar Threads
Null Pointer Exception Help
Accessing JFrame contents
Changing Layout of a Panel in Border Layout
implementing ActionListener and ItemListener
JComboBox selection and counting arrays