| | |
creating dynamic textfields
Thread Solved |
•
•
Join Date: Sep 2004
Posts: 4
Reputation:
Solved Threads: 0
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;
}
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;
}
•
•
Join Date: Sep 2004
Posts: 4
Reputation:
Solved Threads: 0
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;
}
//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;
}
![]() |
Similar Threads
- Creating a Dynamic Library (C++)
- creating dynamic columns and rows with data (PHP)
- Creating dynamic array structures (C++)
- Creating dynamic arrays (C++)
- How will I Capture this Dynamic Data (ASP.NET)
- Creating dynamic Reports (ASP.NET)
- Help with dynamic menu (HTML and CSS)
Other Threads in the Java Forum
- Previous Thread: i need help with my program guys, how to
- Next Thread: I need help with matrix....please!!!
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card class classes client code collision columns component constructor crashcourse database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress integer intellij j2me java javadoc javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle physics plazmic print problem program programming project recursion scanner server set sharepoint smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads tree trolltech unlimited utility webservices windows





