Java 问题: 用两个按钮分别为上一页,下一页,来控制 JTextArea,如何实现滚动条通过点击上下页按钮来

自动向下滚动!实现 看txt文档在 JTextArea中“上下页翻页的的效果”!
中间是我打开的 txt 放到 了 JTxtxtArea 里,就是点一下自动向下拉这个框框这么大的距离,
从而实现“翻页”的效果(就是滚动条向下拉)但是 中间字体以改变,JTextArea里行就变少了,
很不知道怎么实现求 大神或加我qq :1061368470
谢谢,提供思路也可以

使用DefaultEditorKit类提供的pageUpAction,pageDownAction翻页。
自动翻页使用javax.swing.Timer调用追问

大神,可以不可以 实现个例子。我是个新手,谢谢 可以给您多加财富值!谢谢,

追答

final DefaultEditorKit kit = new DefaultEditorKit();
final JTextArea jta = new JTextArea();
final Document doc = jta.getDocument();
final JButton pageUp = new JButton("上一页");
final JButton pageDown = new JButton("下一页");

final Action[] actions = kit.getActions();
for(Action action : actions){
String name = (String) action.getValue(Action.NAME);

if(DefaultEditorKit.pageUpAction.equals(name))
pageUp.addActionListener(action);
else if(DefaultEditorKit.pageDownAction.equals(name))
pageDown.addActionListener(action);
else continue;

}

// load text
kit.read(new FileReader(file), doc,0);

温馨提示:答案为网友推荐,仅供参考
相似回答