RE: "In 1.4 swing seems to be under..."
Right!!  My mind (or my typing fingers) slipped a cog. Swing has always been in "javax.swing.*" (except when it was "com.sun.swing.*", but we don't want to go there).  It has *NEVER* been in "java.swing.*".
 
RE: "You may not be using the FontMetrics..."
Errr... getFontMetrics() is a method of java.awt.Component, the root of the AWT component inheritance tree.  If your Dialog box is an AWT or Swing Component *AT ALL* you can get the font metrics.
 
RE: "A look at the source code..."
Take another look. :^)  The method does not "iterate through" to "the required line length", it *starts* at the required line length and then iterates backward looking for whitespace.
 
-- Roger
-----Original Message-----
From: Burnett, David [mailto:[EMAIL PROTECTED]]
Sent: Monday, January 20, 2003 7:59 PM
To: JDJList
Subject: [jdjlist] RE: String segmentation??? (was: RE: Slow: string += s tring)

I agree that you will want to break the lines at whitespace (or use some hyphenation rules), rather than cut mid-word.
You may not be using the FontMetrics that java.swing.text.Utilities (in 1.4 swing seems to be under javax) requires,
if it is a simple Dialog box (then again....).
 
A look at the source code for getBreakLocation() gives you the general idea - iterate through the string/charArray for
the required line length - then go back to the last whitespace (copy as you go - keep a pointer to the last whitespace etc).
 
db
 
-----Original Message-----
From: Roger Glover [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, January 21, 2003 11:27 AM
To: JDJList
Subject: [jdjlist] RE: String segmentation??? (was: RE: Slow: string += s tring)

I may be missing something here, but what the hey...
 
Wouldn't it be easier (and likely very efficient, if not optimal) to use java.swing.text.Segment and java.swing.text.Utilities.getBreakLocation() ?
 
-- Roger Glover
   glover_roger
-----Original Message-----
From: Greg Nudelman [mailto:[EMAIL PROTECTED]]
Sent: Monday, January 20, 2003 4:05 PM
To: JDJList
Subject: [jdjlist] RE: String segmentation??? (was: RE: Slow: string += s tring)

I have to test this, but I think substring is probably adequate for most purposes.  The other way to go would be to is to use a char array, as below.  I don't know which one is faster -- my hunch is it depends on the size and number of String objects created.
 
char[] c = myString.toCharArray();
int paragraphLength = 35;
int fullArrayLength = c.length;
 
Vector splitStrings = new Vector(fullArrayLength/paragraphLength + 1);
StringBuffer splitString = null;
for(int j = 0; j < fullArrayLength/paragraphLength; j++) {
    splitString = new StringBuffer();
    for(int i = 0; i < paragraphLength; i++) {
        splitString.append(c[j*paragraphLength + i]);
    }
    splitStrings.addElement(splitString.toString());
}
 
You guys might want to test this one if you want to use it -- I may have some off by 1 errors or something...
 
Greg
-----Original Message-----
From: Patrick Li [mailto:[EMAIL PROTECTED]]
Sent: Monday, January 20, 2003 1:21 PM
To: JDJList
Subject: [jdjlist] String segmentation??? (was: RE: Slow: string += string)

While we are talking about string concatenation, what about truncation? Is there a more efficient way to break a long string into segments than using substring()? For example, if I read a paragraph into a string and then wants to break it into line depending on the size of dialog box that will display the paragraph. What is the most efficient way of doing that?
 
Thanks in advance
 
Patrick Li
____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________
____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________
____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________
____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________
____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________

Reply via email to