代码如下:import java.awt.*;
import javax.swing.*;public class MyScroll extends JFrame {

/************创建组件*************/
JPanel centerPanel = new JPanel();

JTextArea textArea1 = new JTextArea();
JLabel blankLabel = new JLabel("              ");
JScrollPane scroll = new JScrollPane(textArea1); 

/******************主函数*********************/
public static void main(String[] args) {
new MyScroll("月满西楼");
}

/**************构造函数**************/
public MyScroll(String title) {
super( "与 " + title + " 聊天中...");
centerPanel.setBackground(new Color(110,204,255));
centerPanel.setLayout(new BoxLayout(centerPanel,BoxLayout.X_AXIS));
textArea1.setPreferredSize(new Dimension(200,200));

add(scroll);
add(centerPanel);

//点关闭,释放窗口
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
// 设置Window的布局管理器为BoxLayout
this.setLayout(new BoxLayout(this.getContentPane(), BoxLayout.Y_AXIS));
this.setSize(300, 240);
this.setLocationRelativeTo(this);
this.setResizable(false);
this.setVisible(true);
}}大伙给个解决方法吧,多谢啦!
请不要删除“textArea1.setPreferredSize(new Dimension(200,200));”这句话,谢谢啦!