3
我想輸出大量的數據(成員資格記錄)到JTextArea中,然後將其轉儲到scrollPane中。這是代碼。scrollpane不工作
package Ginfo;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.io.*;
public class ReviewAll extends JFrame implements ActionListener {
Container RA;
JPanel ReviewAll;
JTextArea output;
JButton back, quit;
Message m;
ConnectInfo c;
ObjectOutputStream oout;
ObjectInputStream oin;
public ReviewAll(ObjectOutputStream oout2, ObjectInputStream oin2,
Message m2, ConnectInfo a) {
super("Full results");
m = m2;
c = a;
oout = oout2;
oin = oin2;
try {
oout.reset();
} catch (IOException e) {
}
RA = getContentPane();
BuildGUI();
RA.add(ReviewAll);
pack();
setLocationRelativeTo(null);
setVisible(true);
try {
m.type = Message.REVIEWALL;
oout.writeObject(m);
while (!m.response.equals("End of list")) {
m = (Message) oin.readObject();
output.append("Member: " + m.main + "\n");
output.append("Invited by: " + m.invitedBy + " on " + m.when
+ "\n");
output.append("Recommended by: " + m.HDTH + "\n\n");
}
m.response = "";
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
private void BuildGUI() {
ReviewAll = new JPanel();
output = new JTextArea();
output.setPreferredSize(new Dimension(400, 400));
output.setEditable(false);
JScrollPane scrollPane = new JScrollPane(output);
scrollPane
.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
back = new JButton("Close window");
quit = new JButton("Exit Program");
ReviewAll.add(scrollPane, BorderLayout.NORTH);
ReviewAll.add(back, BorderLayout.SOUTH);
ReviewAll.add(quit, BorderLayout.SOUTH);
back.addActionListener(this);
quit.addActionListener(this);
}
public void actionPerformed(ActionEvent re) {
if (re.getSource() == back) {
new WhatToDo(oout, oin, m, c);
dispose();
} else if (re.getSource() == quit) {
if (oout != null) {
try {
oout.flush();
oout.close();
oin.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
System.exit(0);
}
}
}
當我這樣做,雖然,我只看到前5條記錄(足以填充我的JTextArea),不能向下滾動查看其餘。對於記錄,當發送記錄保存在list.size()時,我在服務器代碼中將m.response =「End of List」傳送到客戶端(下面列出),我知道這是正確的。我知道這是一個滾動問題。先謝謝您的幫助。
工作就像一個魅力!謝謝! –
@MattWestlake:你很受歡迎! –