Java Swing DefaultListModel containing storing more information -


i created class store 2 properties

public class mailentry {     private string mail;     private mailformat format; // enum      public mailentry(string mail, mailformat format) {         this.mail = mail;         this.format = format;     }      public string getmail() {         return mail;     }      public mailformat getformat() {         return format;     } } 

the jlist created me netbeans gui declared by

    private javax.swing.jlist<string> jlist1; 

and initialized defaultlistmodel

private defaultlistmodel<mailentry> listmodel = new defaultlistmodel<>(); 

and set model

jlist1.setmodel(listmodel); 

but

 error: incompatible types: defaultlistmodel<mailentry> cannot converted listmodel<string>     jlist1.setmodel(listmodel); 

it seems jlist expects model of strings. i'd store more item-specific information, accessible through gui.

how can work around?

the problem you've decleared jlist1 as...

private javax.swing.jlist<string> jlist1; 

but you're declaring model as...

defaultlistmodel<mailentry> listmodel = new defaultlistmodel<>(); 

mailentry , string not compatible classes , jlist expecting listmodel<string> based model.

you need change jlist declaration support model, like

private javax.swing.jlist<mailentry> jlist1; 

since you're using netbean's form editor (don't me started), need select jlist "navigator"

navigator

select "code" tab "properties" tab...

properties

and change type parameters meet requirements


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -