我这里有点问题。我正在使用 javamail API 从我的“收件箱”文件夹中提取我的电子邮件,该部分工作得很好,我遇到的问题是,我试图将它们放入 JTable 中,如下面的代码所示:
try
{
inbox.open(Folder.READ_ONLY);
final Message[] messages = inbox.getMessages(1,20);
System.out.println("NUMBER OF MESSAGES: " + inbox.getMessageCount());
String[] colHead = {"Subject", "Send Date"};
for( int i = 0; i < messages.length; i++)
{
String[] heads = {"Subject", "Sender", "Send Date", "Content"};
Object[][] data = {
{messages[i].getSubject(), (InternetAddress.toString(messages[i].getFrom())), messages[i].getReceivedDate(), messages[i].getContent()}
};
final JTable table = new JTable(data, heads);
final int xyz = i;
panel_6.add(table);
props2 属性在上面定义为:
Properties props2 = new Properties();
props2.setProperty("mail.store.protocol", "imaps");
try
{
Session session = Session.getDefaultInstance(props2, null);
Store store = session.getStore("imaps");
store.connect(imapServer, imapUser, imapPass);
Folder inbox = store.getFolder("Inbox");
我遇到的问题是我希望能够使该 JTable 可滚动,但是如果我创建一个 JScrollPane jsp = new JScrollPane(table) 然后将其而不是表添加到 panel_6,则该表仅显示 1 个结果而不是 20 我应该从 inbox.getMessages(1,20); 如果我让表格不可滚动,它工作正常,我能做些什么吗?谢谢!