程序如下:
public class ServerFrame extends JFrame {
JPanel contentPane;//所有的文本区
JTextArea jTA_get = new JTextArea(); //消息接收文本区
//所有滚动条
JScrollPane jScrollPane1 = new JScrollPane(); //消息接收文本区滚动条
//Construct the frame
public ServerFrame() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
} //Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(null);
this.setSize(new Dimension(700, 600));
this.setTitle("服务端");
this.setResizable(false);
//消息接收文本框和它的滚动条
jTA_get.setFont(new java.awt.Font("Dialog", 0, 15));
jTA_get.setBorder(BorderFactory.createEtchedBorder());
jTA_get.setBounds(new Rectangle(25, 25, 375, 355));
//jScrollPane1= new JScrollPane(jTA_get);
jScrollPane1.setViewportView(jTA_get);
jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
jScrollPane1.setAutoscrolls(true);
jScrollPane1.setBounds(new Rectangle(400, 25, 25, 355));
//组件的添加
contentPane.add(jTA_get,null);
contentPane.add(jScrollPane1, null);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
}
急求,我JTextArea的内容已满了,为什么不能滚动??????我是在JBuilderX里面做的程序
public class ServerFrame extends JFrame {
JPanel contentPane;//所有的文本区
JTextArea jTA_get = new JTextArea(); //消息接收文本区
//所有滚动条
JScrollPane jScrollPane1 = new JScrollPane(); //消息接收文本区滚动条
//Construct the frame
public ServerFrame() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
} //Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(null);
this.setSize(new Dimension(700, 600));
this.setTitle("服务端");
this.setResizable(false);
//消息接收文本框和它的滚动条
jTA_get.setFont(new java.awt.Font("Dialog", 0, 15));
jTA_get.setBorder(BorderFactory.createEtchedBorder());
jTA_get.setBounds(new Rectangle(25, 25, 375, 355));
//jScrollPane1= new JScrollPane(jTA_get);
jScrollPane1.setViewportView(jTA_get);
jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
jScrollPane1.setAutoscrolls(true);
jScrollPane1.setBounds(new Rectangle(400, 25, 25, 355));
//组件的添加
contentPane.add(jTA_get,null);
contentPane.add(jScrollPane1, null);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
}
急求,我JTextArea的内容已满了,为什么不能滚动??????我是在JBuilderX里面做的程序
并且把jScrollPane1.setBounds()参数改下400,25,375,355
jTA_get.setBounds(new Rectangle(25, 25, 375, 355));
也可以去掉。
JTextArea加到JScrollPane的视口中之后,只需要设置JScrollPane的边框和大小就行了。jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
jScrollPane1.setAutoscrolls(true);
也可以不要,前两句不要的话可以自动根据JTextArea的大小动态显示和隐藏滚动条,
第三句本来缺省就是true,不需要再设置一次。