0

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!

3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by aanders5
0

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?

0

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.

0

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)

0

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

Edited by aanders5: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.