Hey I want to make a program with a lot of buttons and rather than declaring and adding each one separately I want to use two for loops one for row and one for columns but I'm not sure how do I add them to the pane do I add them inside the for loops for declaring them or a separate loop for the adding??
|
Java
Add alot of buttons to GUI |
|
Mar 18, 2014 02:03 AM
(This post was last modified: Mar 18, 2014 02:03 AM by SIM-2015410.)
You can't declare variables dynamically, but you CAN dynamically initialise and add them to the pane in the for loop. You could declare a multidimensional array of JBUTTON for rows and columns, then initialise them in the for loop like this:
Code JButton[][] buttons = new JButton[6][6];(Mar 20, 2014 12:22 AM)Pacina Wrote: Sorry for the delay replying to this thread been really busy last few days thanks for the posts exactly what I was looking for Sweet, glad to help out 🙂 PM me if you have any more questions |
|
|


