一个关于JTextPane的setText函数的问题 一个关于JTextPane的setText函数的问题如果字符串参数的长度超出JTextPane的原先文本长度,大约33200-34000时JTextPane就一片空白,即使原来有内容,也变成了空白大家碰到过吗如何应对? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 for(int i=1; i<2000;i++) { msg+="1A2B3C4D5E6F7G8H9I0J\n"; } String txt = textPane.getText(); textPane.setText(txt + msg); 超过长度可以 加... 啊 或者你再弄一个 JtextPane 来翻页 显示 我用JtextPane作为LOG的输出有新LOG内容时,希望JtextPane中旧内容自动上滚不要手动翻页 刚睡醒给你写完了。功能是:开始在textPane中输入今天的时间,然后当你按下那个button之后,添加2000行的字符串。你看看行么。import java.awt.*;import java.awt.event.*;import java.util.*;import javax.swing.*;public class Test extends JFrame{ private JPanel panel; private JTextPane textPane; private JScrollPane scrollPane; private JButton button; private StringBuffer strBuffer = new StringBuffer();; public Test(){ super("Test Add Text"); panel = new JPanel(); textPane = new JTextPane(); textPane.setText(new Date().toString() +": "); textPane.setEditable(false); scrollPane = new JScrollPane(textPane); scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); button = new JButton("Add Text"); button.setPreferredSize(new Dimension(50, 25)); button.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e){ for(int i=1; i <2000;i++) { strBuffer.append("1A2B3C4D5E6F7G8H9I0J\n"); } String text = textPane.getText(); textPane.setText(text + strBuffer.toString()); } } ); panel.setLayout(new BorderLayout()); panel.add(scrollPane, BorderLayout.CENTER); panel.add(button, BorderLayout.SOUTH); setLayout(new BorderLayout()); add(panel, BorderLayout.CENTER); setSize(500, 200); setVisible(true); } public static void main(String args[]){ new Test(); }} 当你频繁做字符串连接的时候,最好用StringBuffer或者StringBuilder 不要用String javase 基础问题 什么叫做封装 关于匿名内部类的一个小疑惑 关于文件路径的一个问题 Java 输入输出问题 急问一个棘手的问题!! 哪个编译环境能运行如下程序啊? 如何在同一虚拟机的两个进程之间交换数据? jcreator pro 2.5,jdk1.4rc,这个接口怎么编译不了? weblogic 的 jdbc for sqlserver 如何解密??他根本都不让我用,气死我了 maven使用Tomcat插件部署,Tomcat启动成功,但localhost报404 swing文本域的问题 容器设置透明
{
msg+="1A2B3C4D5E6F7G8H9I0J\n";
}
String txt = textPane.getText();
textPane.setText(txt + msg);
有新LOG内容时,希望JtextPane中旧内容自动上滚
不要手动翻页
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;public class Test extends JFrame{
private JPanel panel;
private JTextPane textPane;
private JScrollPane scrollPane;
private JButton button;
private StringBuffer strBuffer = new StringBuffer();;
public Test(){
super("Test Add Text");
panel = new JPanel();
textPane = new JTextPane();
textPane.setText(new Date().toString() +": ");
textPane.setEditable(false);
scrollPane = new JScrollPane(textPane);
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
button = new JButton("Add Text");
button.setPreferredSize(new Dimension(50, 25));
button.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
for(int i=1; i <2000;i++) {
strBuffer.append("1A2B3C4D5E6F7G8H9I0J\n");
}
String text = textPane.getText();
textPane.setText(text + strBuffer.toString());
}
}
); panel.setLayout(new BorderLayout());
panel.add(scrollPane, BorderLayout.CENTER);
panel.add(button, BorderLayout.SOUTH);
setLayout(new BorderLayout());
add(panel, BorderLayout.CENTER);
setSize(500, 200);
setVisible(true);
}
public static void main(String args[]){
new Test();
}
}