难道没有人可以解决我的问题吗? 高手在哪啊

harmicle 2005-11-22 12:11:30
下面的代码可直接编译执行;
程序大概的意思就是,一个线程向多个Tab页中的文本框插入文本内容,

奇怪的现象是,总有几个Tab页中的文本框显示的文本内容格式排列有问题,
明明是一行一条内容,但是显示的却是某些部分一行几条内容 :(
而且格式混乱的得还有点规则,:P
只是那些地方的文本不能选择、编辑。

本人在1.3和1.4中都试过,一样的现象,另外系统是XP。

各位大侠帮帮忙,分析分析呵。。。。。。

/*
* Created on 2005-11-21
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package com.freedom.test;

/**
* @author Freedom.Fanglh
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
import javax.swing.*;
import javax.swing.text.*;
import java.awt.*;

public class FRTextTest extends JFrame {

JTabbedPane tabPane = new JTabbedPane();

public static void main(String[] args)
{
FRTextTest f = new FRTextTest();
f.show();
}

public FRTextTest() {
init();
threadTest();
}

private void init() {
getContentPane().add(tabPane);
initTexts(10);
}

private void initTexts(int num) {
for (int i = 0; i < num; i++) {
tabPane.addTab("TAB " + i,new FRTabPage());
}
}

private void threadTest()
{
new Thread(){
public void run()
{
int nums = tabPane.getComponentCount();
for(int j=0;j<200;j++){
try{
Thread.sleep(100);
}
catch(Exception ex){}

for(int i=0;i<nums;i++)
{
FRTabPage page = (FRTabPage)tabPane.getComponentAt(i);
try{
Document doc = page.getTextPane().getDocument();

String content = "I Love This Game\t" + j + "\n";

doc.insertString(doc.getLength(),content,null);


}
catch(BadLocationException ex)
{

}
int maxSV = page.getScrollPane().getVerticalScrollBar().getMaximum();
page.getScrollPane().getVerticalScrollBar().setValue(maxSV);
}
}

}
}.start();
}

public class FRTabPage extends JPanel {

JTextPane textPane = new JTextPane();
JScrollPane scrPane = new JScrollPane();

public FRTabPage() {
initPage();
}

private void initPage() {
scrPane.getViewport().add(textPane);

JSplitPane splitPane =
new JSplitPane(
JSplitPane.VERTICAL_SPLIT,
true,
scrPane,
new JTextPane());

splitPane.setDividerLocation(300);
splitPane.setDividerSize(5);

setLayout(new BorderLayout());
add(splitPane);
}

public JTextPane getTextPane() {
return textPane;
}

public JScrollPane getScrollPane() {
return scrPane;
}
}
}

...全文
126 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
beyondhuangjie 2005-11-25
  • 打赏
  • 举报
回复
懒得看代码。
是不是线程同步问题

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧