on 03-14-2007 8:22 PM
I am trying to retrieve a string from a Java UI in order to detect if bold formatting has been applied. If so, we want to count the number of bolded words in order to send a surcharge to the pricing system that lives in the ABAP stack.
What is the best way to detect bold formatting on this string? Would it be to convert it to XML and if so, how to convert?
I gues you use Swing on the client side.
First you need to get the component which contains the string you want to count. For instance, it could be a JLabel,....
method getFont() will give your a Font instance. YOu can check if it equals to Font.BOLD.
Dennis
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Dennis,
I don't think this would work because I believe this will return an instance of a font from the whole component.
In this case it is possible to have different types of fonts (bold and italic) and I would need to count the various instances of bold formatting applied to the string.
Thanks though,
Michael
Ok.
If you set the text for JLabel as HTML, you just need to count the <BOLD> tags and its contents.
For instance, if the text is in this way,
"<html><B>Bold</B> and <I>Italic</I> Text <B>Bold again</B></html>"
There are a lot of ways to count the bold texts.
For example,
String text = "<html><B>Bold</B> and <I>Italic</I> Text <B>Bold again</B></html>";
StringBuffer buffer = new StringBuffer();
while( text.length() > 0 )
{
int index = text.indexOf("<B>");
if ( index != -1 )
{
buffer.append( text.subString(index+3, text.indexOf("</B>")));
text = text.subString( text.indexOf("</B>" + 4));
}
else
{
break;
}
}
If you don't set the text in html format, ignore my comment.
Dennis
<html><B>Bold</B> and <I>Italic</I> Text <B>Bold again</B></html>
String text = "<html>Bold and Italic Text Bold again</html>"; StringBuffer buffer = new StringBuffer(); while( text.length() > 0 ) { int index = text.indexOf(""); if ( index != -1 ) { buffer.append( text.subString(index+3, text.indexOf(""))); text = text.subString( text.indexOf("" + 4)); } else { break; } }
Thanks Dennis,
We actually decided to go another route. Instead of parsing to XML, which was proving very difficult, we discovered that a method was called within the Java UI whenever bold formatting was turned on. We are incrementing based on this.
Michael
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.