creating dynamic textfields

Thread Solved

Join Date: Sep 2004
Posts: 4
Reputation: perky_jing is an unknown quantity at this point 
Solved Threads: 0
perky_jing perky_jing is offline Offline
Newbie Poster

creating dynamic textfields

 
0
  #1
Sep 17th, 2004
how do i make the number of my textfileds dynamic? the number of my textfield depends on the parameter passed through the method setDetailsPanel(int s). the variable s determines the number of textfield i need.

i'm having this type of error. i don't seem to get the reason why.
D:\Program Files\Xinox Software\JCreator LE\MyProjects\Admin\Admin.java:563: incompatible types
found : javax.swing.JTextField[]
required: javax.swing.JTextField
txtSname[i] = new JTextField[s];
^
//THE CODE
public JPanel setDetailsPanel(int s) {
JTextField[] txtSname;
JTextField[] txtSage;
JTextField[] txtSschool;

sBtn.setVisible(false);
JPanel detailsPanel = new JPanel(new BorderLayout());
JPanel labelPanel = new JPanel();
JLabel lblSname = new JLabel("Name", JLabel.LEFT);
JLabel lblSage = new JLabel("Age", JLabel.CENTER);
JLabel lblSschool = new JLabel("School", JLabel.RIGHT);
labelPanel.add(lblSname);
labelPanel.add(lblSage);
labelPanel.add(lblSschool);
detailsPanel.add(labelPanel, BorderLayout.NORTH);

int i=1;
JPanel tp;
JPanel textFields = new JPanel(new GridLayout(s,1));

while (i<=s) {
tp = new JPanel();
txtSname[i] = new JTextField[s];
txtSage[i] = new JTextField[s];
txtSschool[i] = new JTextField[s];
tp.add(txtSname[i]);
tp.add(txtSage[i]);
tp.add(txtSschool[i]);
textFields.add(tp);
i++;
}

detailsPanel.add(textFields, BorderLayout.CENTER);

return detailsPanel;
}
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 4
Reputation: perky_jing is an unknown quantity at this point 
Solved Threads: 0
perky_jing perky_jing is offline Offline
Newbie Poster

Re: creating dynamic textfields

 
0
  #2
Sep 17th, 2004
GUYS, PLEASE DON'T MIND MY QUESTION. MINUTES AFTER I POST THIS QUESTION I REVIEWED MY CODE AND FOUND OUT WHERE I WAS DOING WRONG. I'VE BEEN PONDERING ON WHAT TO DO WITH THIS DYNAMIC THING BEFORE I RESULT INTO AN ARRAY OF TEXTFIELDS. AND IT TOOK ME SO LONG TO FIGURE OUT HOW AND I'VE BEEN SO FRUSTRATED ON FINDING THE ANSWER. ANYWAY, I HOPE YOU COULD HELP ME IF EVER I COME ACROSS WITH ANOTHER PROBLEM.

//THE CODE
public JPanel setDetailsPanel(int s) {
sBtn.setVisible(false);
JPanel detailsPanel = new JPanel(new BorderLayout());
JPanel labelPanel = new JPanel();
JLabel lblSname = new JLabel("Name", JLabel.LEFT);
JLabel lblSage = new JLabel("Age", JLabel.CENTER);
JLabel lblSschool = new JLabel("School", JLabel.RIGHT);
labelPanel.add(lblSname);
labelPanel.add(lblSage);
labelPanel.add(lblSschool);
detailsPanel.add(labelPanel, BorderLayout.NORTH);

int i=1;
JPanel tp;
JPanel textFields = new JPanel(new GridLayout(s,1));
JTextField[] txtSname = new JTextField[s];
JTextField[] txtSage = new JTextField[s];
JTextField[] txtSschoo = new JTextField[s]l;


while (i<=s) {
tp = new JPanel();
txtSname[i] = new JTextField(15);
txtSage[i] = new JTextField(2);
txtSschool[i] = new JTextField(2);
tp.add(txtSname[i]);
tp.add(txtSage[i]);
tp.add(txtSschool[i]);
textFields.add(tp);
i++;
}

detailsPanel.add(textFields, BorderLayout.CENTER);

return detailsPanel;
}
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC