Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Error(23,19): method getName(java.lang.String) not found in class javax.swi

800647Jan 3 2009 — edited Jan 3 2009
Hi , when i try to run my program, i keep getting the error msg:

Error(23,19): method getName(java.lang.String) not found in class javax.swing.JTextField

I have checked the java API and it inherits from the awt.Component class and should be accessible via the jtextfield.

I have tried the following:
trying to initailise the JTextField at the start.
Using getName works if i use it within the loop after setting the name.

Does anybody know what i am doing wrong please?
public class clsMember extends JPanel implements ActionListener {
    private JButton jbtnLog;
    private String surname;
    private JTextField txtItem;
        
    public clsMember() {
        super(new SpringLayout());
        makeInterface();
        surname = txtItem.getName("Surname").toString();
    }

 private void makeInterface() {
     //code omitted

           for (int i = 0; i < numpairs; i++) {
            JLabel l = new JLabel(strLabels, JLabel.LEADING);
this.add(l);
//if the array item is salutation create a combobox
if (strLabels[i] == "Salutation") {
jcomSalutation = new JComboBox(strSalutation);
jcomSalutation.setSelectedIndex(0);
this.add(jcomSalutation);
} else {
txtItem = new JTextField(10);
l.setLabelFor(txtItem);
txtItem.setName(strLabels[i].replaceAll(" ", "")); //this is where the label is set and if i do a system.out it shows fine. getName works here too.
this.add(txtItem);
}
}
//code omitted
}
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 31 2009
Added on Jan 3 2009
12 comments
506 views