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;
}