cancel
Showing results for 
Search instead for 
Did you mean: 

Detecting bold formatting

Former Member
0 Kudos

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?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos
<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; } } 

Answers (1)

Answers (1)

Former Member
0 Kudos

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