United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4510123 : JTextArea.setWrapStyleWord() cannot handle the composed string properly

Details
Type:
Bug
Submit Date:
2001-10-03
Status:
Closed
Updated Date:
2003-10-16
Project Name:
JDK
Resolved Date:
2003-07-11
Component:
client-libs
OS:
linux,generic
Sub-Component:
javax.swing
CPU:
x86,generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
1.4.0,1.4.1,1.4.2
Fixed Versions:
5.0 (tiger)

Related Reports
Duplicate:
Relates:

Sub Tasks

Description
Reproduction:

- Extract the attached test case, JTextAreaTest.java.
- Compile and Execute the test case.
  % java JTextAreaTest

The test case includes one line sentence which is composed of 1 byte characters
and 2 bytes characters but the word-wrapping is an unnatural.  It should be
wrapped one character at a time in Japanese.  And also the location of the caret
which pointed by mouse on the place wrapped and no characters is actually on the different place.

###@###.### 2001-10-03

                                    

Comments
SUGGESTED FIX



Name: pzR10082			Date: 06/05/2003


*** /net/crown/export1/zpm/webrev/src/share/classes/javax/swing/text/Utilities.java-	Thu Jun  5 14:53:09 2003
--- Utilities.java	Thu Jun  5 14:44:52 2003
***************
*** 190,197 ****
  
      /**
       * Determine where to break the given text to fit
!      * within the the given span.  This tries to find a
!      * whitespace boundary.
       * @param s  the source of the text
       * @param metrics the font metrics to use for the calculation
       * @param x0 the starting view location representing the start
--- 190,196 ----
  
      /**
       * Determine where to break the given text to fit
!      * within the given span. This tries to find a word boundary.
       * @param s  the source of the text
       * @param metrics the font metrics to use for the calculation
       * @param x0 the starting view location representing the start
***************
*** 211,225 ****
  	int txtCount = s.count;
  	int index = Utilities.getTabbedTextOffset(s, metrics, x0, x, 
  						  e, startOffset, false);
- 	for (int i = txtOffset + Math.min(index, txtCount - 1); 
- 	     i >= txtOffset; i--) {
  	    
  	    char ch = txt[i];
! 	    if (Character.isWhitespace(ch)) {
! 		// found whitespace, break here
! 		index = i - txtOffset + 1;
! 		break;
! 	    }
  	}
  	return index;
      }
--- 210,239 ----
  	int txtCount = s.count;
  	int index = Utilities.getTabbedTextOffset(s, metrics, x0, x, 
  						  e, startOffset, false);
  	    
+ 
+         if (index >= txtCount - 1) {
+             return txtCount;
+         }
+ 
+ 	for (int i = txtOffset + index; i >= txtOffset; i--) {
  	    char ch = txt[i];
!             if (ch < 256) {
!                 // break on whitespace
!                 if (Character.isWhitespace(ch)) {
!                     index = i - txtOffset + 1;
!                     break;
!                 }
!             } else {
!                 // a multibyte char found; use BreakIterator to find line break
!                 BreakIterator bit = BreakIterator.getLineInstance();
!                 bit.setText(s);
!                 int breakPos = bit.preceding(i + 1);
!                 if (breakPos > txtOffset) {
!                     index = breakPos - txtOffset;
!                 }
!                 break;
!             }
  	}
  	return index;
      }

###@###.### 

======================================================================
                                     
2004-08-24
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
tiger

FIXED IN:
tiger

INTEGRATED IN:
tiger
tiger-b11

VERIFIED IN:
tiger-beta


                                     
2004-08-24
WORK AROUND

Use JTextPane, create a ViewFactory that uses LabelView for rendering, or set the i18n property of the document.
###@###.### 2001-10-03

You can set the i18n property by way of:

textComponent.getDocument().putProperty("i18n", Boolean.TRUE);
###@###.### 2003-10-28
                                     
2001-10-03
EVALUATION

WrappedPlainView is currently using whitespace to determine breaking, it should use BreakIterator if there are chars > 255 in the document.
###@###.### 2001-10-03
                                     
2001-10-03



Hardware and Software, Engineered to Work Together