• Post Reply Bookmark Topic Watch Topic
  • New Topic

how t ouse JPanel as an array URGENT

 
ghazanfar khan
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I m dynamically generating JTextField when i click on button, i want to store that JTextField in to an JPanle array.

But it is giving me an error. It is very urgent please
JPanel j = new JPanel();
JPanel[] arr = new JPanel[5];

JTextField t = new JTextField(9);
j.add(t);
arr[0].add(j) /// here it is thrlwing an eror
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JPanel[] arr = new JPanel[5];//this does not 'create' 5 JPanels

JTextField t = new JTextField(9);
j.add(t);
arr[0] = new JPanel();//JPanel created with this line
arr[0].add(j) /// here it is thrlwing an eror


best solution is to create all 5 panels together
for(int x = 0; x < arr.length; x++) arr[x] = new JPanel();
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!