I put a bunch of JButtons in a 2D array into a GridLayout. I want the user to be able to change the size of this grid at run time, but I tried resetting the row/cols, re-adding the buttons, remaking the panel that this grid is in - all to no avail. How do I accomplish this?
When I execute it and put in a number smaller than the original size (5), it'll add a bunch of new buttons to the existing ones. I don't know why it doesn't work for larger numbers either since I (at least seem to have) changed the rows and cols of the layout before looping through and adding new things--error occurs right before the adding-for loop. I guess I'm going about setRows/setColumns wrong since they're apparently not doing anything?
Haven't changed the code at all - just replaced newSize = in.nextInt(); with newSize = 7; as you suggested. I still have no idea what the problem is with regards to removing components (in remakeGrid()) so I don't know what else to change further.
Where do you remove the components from the container?
Alright, thanks - that's what I was having trouble with. The first time I tried calling remove(), I got an error, so I thought that wasn't the way to go but from your reminder I tried it again and it's fine now.
Apparently I don't need a new layout manager, as far as I've tested it...