//c.javaimport java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;class MainWindows extends JFrame implements ActionListener
{
public JTextArea JTextArea1=new JTextArea("welcome");
public JTextField JTextField1=new JTextField("请输入要发送内容");
public JButton button1=new JButton("发送");
public void Windows()
{
Container con=getContentPane();
con.setLayout(new FlowLayout());
con.add(JTextArea1);
con.add(JTextField1);
con.add(button1);
button1.addActionListener(this);
JTextField1.setPreferredSize(new Dimension(395, 30));
JTextArea1.setPreferredSize(new Dimension(390, 280));
setSize(410,420);
setVisible(true);
setResizable(false);
setDefaultCloseOperation(3);
}
public void actionPerformed(ActionEvent actionevent)
{
if(actionevent.getActionCommand().equals("发送"))
{
String s=JTextField1.getText().trim();
JTextField1.setText("");
JTextArea1.append(" "+s+"\n");
if (s.length()==0)
JTextArea1.setText("信息不能为空");
}
}
}
public class c
{
public static void main(String []args)
{
MainWindows n=new MainWindows();
n.Windows();
System.gc();
}
}本程序是从JTextField读取字符,按"发送"打印到JTextArea区域中,
现在的问题是; JTextArea中满的时候不能显示下面的内容,怎么实现JTextArea的自动滚动?有知道的吗?
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;class MainWindows extends JFrame implements ActionListener
{
public JTextArea JTextArea1=new JTextArea("welcome");
public JTextField JTextField1=new JTextField("请输入要发送内容");
public JButton button1=new JButton("发送");
public void Windows()
{
Container con=getContentPane();
con.setLayout(new FlowLayout());
con.add(JTextArea1);
con.add(JTextField1);
con.add(button1);
button1.addActionListener(this);
JTextField1.setPreferredSize(new Dimension(395, 30));
JTextArea1.setPreferredSize(new Dimension(390, 280));
setSize(410,420);
setVisible(true);
setResizable(false);
setDefaultCloseOperation(3);
}
public void actionPerformed(ActionEvent actionevent)
{
if(actionevent.getActionCommand().equals("发送"))
{
String s=JTextField1.getText().trim();
JTextField1.setText("");
JTextArea1.append(" "+s+"\n");
if (s.length()==0)
JTextArea1.setText("信息不能为空");
}
}
}
public class c
{
public static void main(String []args)
{
MainWindows n=new MainWindows();
n.Windows();
System.gc();
}
}本程序是从JTextField读取字符,按"发送"打印到JTextArea区域中,
现在的问题是; JTextArea中满的时候不能显示下面的内容,怎么实现JTextArea的自动滚动?有知道的吗?
解决方案 »
- 菜鸟求助,Date类与GregorianCalender类的区别是什么呢?
- 紧急求助,编程排序问题!!!(送分)
- 新手applet问题!
- 新手关于数据库的问题(在线等答案 100分)
- frame显示问题
- 关于String[]的一个小问题?
- 关于java.util.Timer的问题讨论,高手进来看看
- 我想编程分析任意一个java文件,把其中的注释部分删掉,请帮我分析一下思路和方法好吗?
- 如何将string类型转换成date类型?急
- jcreator2.0pro,在那能下载呢?还有哪个ultraedit的什么插件wordfile.txt,在那里找呢?
- 提取邮件信息
- 关于公共类库的问题,急,在线等~~
jTextArea.append(" "+s+"\n");
jTextArea.setCaretPosition(jTextArea.getText().length();//滾動到底端
看里面的例子:http://www.java2s.com/Code/Java/Swing-JFC/Scrollpane.htm
con.add(jScrollPane );//con.add(JTextArea1);
---------------------------------
jTextArea.append(" "+s+"\n");
jTextArea.setCaretPosition(jTextArea.getText().length();//滾動到底端