944,204 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 8322
  • Java RSS
Sep 17th, 2004
0

creating dynamic textfields

Expand Post »
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;
}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
perky_jing is offline Offline
4 posts
since Sep 2004
Sep 17th, 2004
0

Re: creating dynamic textfields

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;
}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
perky_jing is offline Offline
4 posts
since Sep 2004

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: i need help with my program guys, how to
Next Thread in Java Forum Timeline: I need help with matrix....please!!!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC