Forums Register Login

creating controls at run time

+Pie Number of slices to send: Send
i want to create a componets in swing at run time as control array.

Button b[]=new button[10];

will this work?

how can i change the number of elements in array at run time.

if possible can u demonstarte with an example code.please


THANK U FRIENDS
+Pie Number of slices to send: Send
Welcome to JavaRanch!

Certainly you can use an array to hold references to things like buttons. To set the number of elements at runtime, just pass that number as a variable...

JButton[] myButtons = new JButton[numberOfButtons];

Note, however, that once an array is instantiated, it cannot be resized. For that flexibility, you need something like an ArrayList.

Here's an example in which the command line argument specifies the number of buttons at runtime...

[ March 16, 2006: Message edited by: marc weber ]
Slime does not pay. Always keep your tiny ad dry.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 813 times.
Similar Threads
JSP action help(Basic question)
Changing size of java array
Building Array with jButton
jTable Header Problem
Vector
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:34:21.