[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 206
  • Last Modified:

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
0
waffe
Asked:
waffe
  • 2
1 Solution
 
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now