How do I clear/renew/empty/refresh a 2D JButton Array? I've tried a lot of things, but all that is happening is the new 2D array, just adds onto the old one, which is not what I want. It won't even just overwrite the old array.

So i am not sure what to do. lol
Thanks!

Recommended Answers

All 4 Replies

have you tried reinstanciate the array

public void clear(JButton[][] myArray){
       myArray = new JButton[i][j]; //whatever your dimensions are
   }

can you be a little bit more specific?

Yea I tried that, and I think it is somewhat working now.

But now I can't get the pre-existing JButtons to be overwritten, deleted, or updated, so only the new ones are present.

Do you mean you want to remove them from the array, or remove them from our GUI?
To remove them from the GUI use the remove(..) method (exactly like the add method you used to add them to the GUI)

Yup, I did that. Now after I hit remove, they all stay, but if I move teh java screen off the page all the buttons are gone, and the new ones don't replace them, its just whitespace. :/


So how do I get the screen to at least refresh the image/panel? Or even the frame.
THis is all happening in NetBeans btw

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.