下面的代码可直接编译执行;
程序大概的意思就是,一个线程向多个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;
}
}
}
程序大概的意思就是,一个线程向多个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;
}
}
}
解决方案 »
- 请问这程序怎么写,需要获取网页上的一个验证码的图片,然后通过一个方法(已经在在,设为X(Image a),然后模拟在网页上的一个文本框中输入,然后获取返回值
- 请问jtable中单元格点击怎么弹出日期控件和下拉列表
- 数据库blob类型文件写入本地影片问题
- 请问SWING中如何实时刷新图象
- 大家一起来练习
- 父类数据库表的设计
- 初学java,请问其函数在哪查?就象vc的函数可以在msdn中查一样。。
- 大家看看这是哪种编码方式得到的字符串啊
- 请教:如何终止(退出)这段(阻塞)代码的执行
- 请帮忙:Bean里可以用session吗?如何用?有例程吗? 多谢你一万遍!!!!
- 如何计算当前日期及以后15天的日期啊?
- javamail 特殊的抄送(CC) 在线
------------------
会吗?