public class MovePointPanel extends JPanel implements ActionListener {//要实现该接口 Timer t = null; public MovePointPanel() { t = new Timer(200, this);//没过200毫秒,执行一次actionPerformed方法。时间可以自己修改 t.start(); } public void actionPerformed(ActionEvent event) { //在这里写上你自己的刷新方法。 } }
Timer t = null; public MovePointPanel() {
t = new Timer(200, this);//没过200毫秒,执行一次actionPerformed方法。时间可以自己修改
t.start();
} public void actionPerformed(ActionEvent event) {
//在这里写上你自己的刷新方法。
}
}
我现在看到的效果好像这样做不行!
这样做只能让滚动条自动的出现,但是并不能让滚动条自动下移显示新的消息。
只是你有新消息来了
你需要append("...")进去
我用JTextArea就是这样做的。
JScrollPane scrollpane=new JScrollPane(resultarea);
add(scrollpane);
刚才我试了 setCaretPosition 方法,单纯的设置光标没有用.
不能让滑动条定位到最后.