• Post Reply Bookmark Topic Watch Topic
  • New Topic

dynamic buttons  RSS feed

 
Victor Casanas
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

In the case where I don't know how many buttons I'll need until runtime how can I dynamically generate button names? It would be something like this using sh:


i = 0
n = <generated at runtime>
while (( i<n ))
do
JButton b_$i = new JButton();
i++;
done

and then I'd have buttons b_0, b_1, b_2, ....




I also need to do this w/ checkboxes, where I want to put a checkbox at the beginning of each line but I don't know in advance how many lines I'll have.


Thanks,
Victor
 
Adrian Marti
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howabout an array of JButtons? Then just iterate over it to display all that were generated.

You can't do variable naming like that AFAIK.

Adrian
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!