简体   繁体   中英

vector data in jlist?

I am trying to display the data in vector in jlist. The below method connect() executes fine, without any error when it is called, but the vector data is not displayed in jlist. My code is:

public void connect(String user, String pass)
{
    vdate = new Vector(); 
    vsubject = new Vector();
    vfrom = new Vector();
    vmessage = new Vector(); 

    final String password = pass;
    final String username = user;

    try
    {

        props = new Properties();
        props.setProperty("mail.host", "imap.gmail.com");
        props.setProperty("mail.port", "995");
        props.setProperty("mail.transport.protocol", "imaps");

        session = Session.getInstance(props,
                new javax.mail.Authenticator() {
                    protected PasswordAuthentication getPasswordAuthentication() {
                        return new PasswordAuthentication(username,password);
                    }
                });

        store = session.getStore("imaps");
        store.connect();
        Folder inbox = store.getFolder("INBOX");
        inbox.open(Folder.READ_ONLY);

        Message messages[] = inbox.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false));

        for (int i = 0; i < messages.length; i++) 
        {  
            Message message = messages[i];
            Address[] from = message.getFrom();
            frm = from[0].toString();
            vfrom.addElement(frm);
            date = message.getSentDate().toString();
            vdate.addElement(date);
            Multipart mp = (Multipart)message.getContent();
            BodyPart bp = mp.getBodyPart(0);
            mess = ""+bp.getContent();
            subject = message.getSubject().toString();
            vsubject.addElement(subject);
        }

        jList1.setListData(vdate);
        jList2.setListData(vsubject);
        jList3.setListData(vfrom);
    } catch (Exception mex) {
        mex.printStackTrace();
    }
}

The for loop executes fine. Also the data gets stored in vector but when I set it to jlist nothing shows up........plz help

jList1.setListData(vdate);
jList1.setListData(vsubject);
jList1.setListData(vfrom);

Every time you invoke the setListData(...) method the data in the JList get replaced. So the best case scenario is that you will get the data in the vFrom Vector.

Just use a single Vector for all the data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM