Dynamically adding form elements to a frame
Hay I have to add form elements to a frame dynamically in a loop.But I have a problem in instantiating those form elements wiz.
String[] s={"a","b","c"};
for(int i=0;i<s.length;i++)
{
JButton s.=new JButton();
this.getcontentPane().add(s);
}
can any body help me in this
>
**correction for the earlier**
Hay I have to add form elements to a frame dynamically in a loop.But I have a problem in instantiating those form elements wiz.
String[] s={"a","b","c"};
for(int i=0;i<s.length;i++)
{
JButton s=new JButton();
this.getcontentPane().add(s);
}
>
Notice that using array index "i" screws up the formatting of your post. It makes the font switch to italics! Anyway...I think what you want to be doing is this:
String[] s={"a","b","c"};
for(int j=0 ; j<s.length ; j++) {
JButton b = new JButton(s[j]);
this.getcontentPane().add(b);
}
>