dynamicly create JButtons

Hi,

For a UI I need to create a row of JButtons. At times this row will need to be 10 JButtons long, at other times, in may need to be 28 JButtons long. I do not want to hard code all these JButtons, is there a way to create them in a for loop dynamicly?

Thanks,

waffe
waffeAsked:
Who is Participating?
 
CEHJCommented:
/* ( JButton[] ) */ buttons = new JButton[NUM_REQUIRED];
for(int i = 0;i < NUM_REQUIRED;i++) {
      buttons[i] = new JButton("Button " + (i + 1));
      container.add(buttons[i]);
 
}
0
 
waffeAuthor Commented:
Perfect!

Thanks,

waffe
0
 
CEHJCommented:
:-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.