java - Receiving emails and storing it in jTable -
i trying receive mails email account. not able store in jtable
. want because when 1 row selected contents displayed in jtextarea
. code snippet.
public void connect() { final string pass = set.pass; final string user = set.uname; try { properties props = new properties(); props.put("mail.imap.host", "imap.gmail.com"); props.put("mail.imap.socketfactory", 995); props.put("mail.imap.socketfactory.class", "javax.net.ssl.sslsocketfactory"); props.put("mail.imap.port", 995); session session = session.getdefaultinstance(props, new authenticator() { @override protected passwordauthentication getpasswordauthentication() { return new passwordauthentication(user, pass); } }); store store = session.getstore("imap"); store.connect("imap.gmail.com", "mymail@gmail.com", "mypaswword"); folder folder = store.getfolder("inbox"); folder.open(folder.read_only); message[] msg = folder.getmessages(); fetchprofile profile = new fetchprofile(); profile.add(fetchprofile.item.envelope); folder.fetch(msg, profile); jtable2.add(msg); folder.close(true); store.close(); } catch (exception e) { system.out.println(e); } }
i getting error in line
jtable2.add(msg);
how supposed it..
add
used add components container rather data jtable
. create custom abstracttablemodel
storing message
references
public class messagetablemodel extends abstracttablemodel { private list<message> messages; public messagetablemodel(list<message> messages) { this.messages = new arraylist<message>(messages); } @override public int getrowcount() { return messages.size(); } @override public int getcolumncount() { return 2; } @override public object getvalueat(int rowindex, int columnindex) { object value = "??"; message message = messages.get(rowindex); switch (columnindex) { case 0: stringbuilder builder = new stringbuilder(); (address a: message.getfrom()) { builder.append(a); builder.append(","); } value = builder.tostring(); break; case 1: value = message.getsubject(); break; } return value; } @override public class<?> getcolumnclass(int columnindex) { return string.class; } /* override if want values editable... @override public void setvalueat(object avalue, int rowindex, int columnindex) { //.... } */ /** * return message @ specified row... * @param row * @return */ public message getmessageat(int row) { return messages.get(row); } }
Comments
Post a Comment