I have textpane getting generated. i need to supercript the text when the text is selected and during click of superscript button, i need to superscript the text. if the text is already superscripted, it needs to unsuperscript the text. My problem is i am able to superscript the text, but unable to restore back. I am checking for the isSuperscript condition, but then every time it returns the value as true and sets the text as superscript. below is the code i am using, can anyone tell me how i can reset the superscripted text.
SimpleAttributeSet sasText = new SimpleAttributeSet(parentTextPane.getCharacterAttributes());
System.out.println("character set 1 " + sasText.toString());
if ( StyleConstants.isSuperscript(sasText) ){
System.out.println("already super");
StyleConstants.setSuperscript(sasText, false);
} else {
System.out.println("needs super");
StyleConstants.setSuperscript(sasText, true);
}
int caretOffset = parentTextPane.getSelectionStart();
parentTextPane.select(caretOffset, caretOffset + textLength);
HTMLDoc.setCharacterAttributes(selStart,textLength,sasText, false);
parentEkit.refreshOnUpdate();
The problem is that parentTextPane.getCharacterAttributes() will return the character attributes for the character after the current caret position. As your selection encompasses your superscript text, the following character is normal. It is the attributes for that following char that you are testing, and the result will be false. You have the option of doing what getCharacterAttributes() (from JTextPane):
public AttributeSet getCharacterAttributes() {
StyledDocument doc = getStyledDocument();
Element run = doc.getCharacterElement(getCaretPosition());
if (run != null) {
return run.getAttributes();
}
return null;
}
except that you want to return the start of your selection:
public AttributeSet getMyCharacterAttributes() {
StyledDocument doc = parentTextPane.getStyledDocument();
Element run = doc.getCharacterElement(parentTextPane.getSelectionStart());
if (run != null) {
return run.getAttributes();
}
return null;
}
Your code would then change to do something like the following:
SimpleAttributeSet sasText = new SimpleAttributeSet(getMyCharacterAttributes());
//... the rest of your code
It works fine for me. I do a quick test with code like:
SimpleAttributeSet green = new SimpleAttributeSet();
System.out.println( StyleConstants.isSuperscript(green) );
StyleConstants.setForeground(green, Color.GREEN);
StyleConstants.setSuperscript(green, true);
System.out.println( StyleConstants.isSuperscript(green) );
StyleConstants.setSuperscript(green, false);
System.out.println( StyleConstants.isSuperscript(green) );
and get the output:
false
true
false
which proves that the attribute is being reset properly. The text is also displayed properly.
If your "sasText" always returns true when you test for the superscript attribute then you must be resetting that attribute somewhere else in your code.
If you need more help post your SSCCE showing the problem.
Related
I'm working on a database program where the GUI has multiple input areas, some of which are JTextPanes where the user can set Bold, Underline, and Italic styles on their text. When the user places their cursor immediately adjacent to an area that is already bold, for example, I want the next text that they type to likewise be bold. So far, the only thing that is happening is that text typed immediately after bolded text is bold, but I cannot seem to make it so that text typed in immediately before bolded text is likewise bold.
I'm not sure that all was any less than confusing, so here's an example:
Presume the sentence, "Java is fun." is already in one of the JTextPanes.
If the user places the cursor to the left or right of "is", I want whatever they type next to likewise be bold. Like this, "Java fooisbar fun."
So far, I am only getting, "Java fooisbar fun."
What follows is the method I am using to add style-detecting functionality to the caret of a JTextPane and what I thought would work to do this.
I've also tried adding an additional new StyledEditorKit.BoldAction().actionPerformed(null) before or after the boldButton.setSelected(true) but that didn't have any effect. I also attempted tp.getStyledDocument().setCharacterAttributes(caretPosition -1, 1, asPrev, true), and while that did make the next text inputted bold, the results were unpredictable, with random line breaks and missing characters happening. Changing boldButton.setSelected(true) to boldButton.doClick() didn't have any effect, nor did using my ButtonAction class to set the text to bold.
int lastCaretPosition;
public void formatAndAddFunctions(Component c) {
Font normalFont = new Font("Tahoma", Font.PLAIN, 11);
c.setFont(normalFont);
if (c instanceof JTextField) {
((JTextField) c).setAlignmentX(Component.LEFT_ALIGNMENT);
((JTextField) c).addFocusListener(new java.awt.event.FocusAdapter() {
#Override
public void focusGained(java.awt.event.FocusEvent evt) {
((JTextField) c).selectAll();
activeComponent = c;
}
});
UndoTool.addUndoFunctionality((JTextField) c);
}
if (c instanceof JScrollPane) {
((JScrollPane) c).setAlignmentX(Component.LEFT_ALIGNMENT);
JViewport vp = ((JScrollPane) c).getViewport();
JTextPane tp = (JTextPane) vp.getView();
tp.setContentType("text/html");
tp.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true);
tp.addFocusListener(new java.awt.event.FocusAdapter() {
#Override
public void focusGained(java.awt.event.FocusEvent evt) {
activeComponent = tp;
}
});
UndoTool.addUndoFunctionality(tp);
//look at the character attibutes before and after the caret to see if they are
//formatted bold, underline, and/or italic
lastCaretPosition = -1;
tp.addCaretListener((CaretEvent ce) -> {
int caretPosition = tp.getCaretPosition();
if(caretPosition != lastCaretPosition) {
lastCaretPosition = caretPosition;
Element charElementPrev = tp.getStyledDocument().getCharacterElement(caretPosition - 1);
AttributeSet asPrev = charElementPrev.getAttributes();
Element charElementAfter = tp.getStyledDocument().getCharacterElement(caretPosition);
AttributeSet asAfter = charElementAfter.getAttributes();
if ((StyleConstants.isBold(asPrev) || StyleConstants.isBold(asAfter)) && !boldButton.isSelected()) {
boldButton.setSelected(true);
} else if((!StyleConstants.isBold(asPrev) && !StyleConstants.isBold(asAfter)) && boldButton.isSelected()) {
boldButton.setSelected(false);
}
if ((StyleConstants.isUnderline(asPrev) || StyleConstants.isUnderline(asAfter)) && !ulButton.isSelected()) {
ulButton.setSelected(true);
} else if ((!StyleConstants.isUnderline(asPrev) && !StyleConstants.isUnderline(asAfter)) && ulButton.isSelected()) {
ulButton.setSelected(false);
}
if ((StyleConstants.isItalic(asPrev) || StyleConstants.isItalic(asAfter)) && !itButton.isSelected()) {
itButton.setSelected(true);
} else if ((!StyleConstants.isItalic(asPrev) && !StyleConstants.isItalic(asAfter)) && itButton.isSelected()) {
itButton.setSelected(false);
}
}
});
tp.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_B, java.awt.event.InputEvent.CTRL_DOWN_MASK), "boldKeystroke");
tp.getActionMap().put("boldKeystroke", new ButtonAction("bold"));
tp.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_U, java.awt.event.InputEvent.CTRL_DOWN_MASK), "underlineKeystroke");
tp.getActionMap().put("underlineKeystroke", new ButtonAction("underline"));
tp.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_I, java.awt.event.InputEvent.CTRL_DOWN_MASK), "italicKeystroke");
tp.getActionMap().put("italicKeystroke", new ButtonAction("italic"));
}
}
And, for reference, the boldButton's code:
boldButton = new JToggleButton();
boldButton.setIcon(allIcons[39]);
boldButton.setRolloverIcon(allIcons[40]);
boldButton.setSelectedIcon(allIcons[41]);
boldButton.setToolTipText("Bold");
boldButton.setBorderPainted(false);
boldButton.setContentAreaFilled(false);
boldButton.setFocusable(false);
boldButton.setBorder(null);
boldButton.setMargin(noInset);
boldButton.addActionListener((java.awt.event.ActionEvent e) -> {
new StyledEditorKit.BoldAction().actionPerformed(e);
activeComponent.requestFocusInWindow();
});
The odd thing is that if I set the cursor right before bolded text, and then click on the Bold toggle button in the UI, the next text typed does come out bold. But I can't seem to get this to happen programmatically. Any ideas?
I have a .docx template with placeholders to be filled, such as ${programming_language}, ${education}, etc.
The placeholder keywords must be easily distinguished from the other plain words, hence they are enclosed with ${ }.
for (XWPFTable table : doc.getTables()) {
for (XWPFTableRow row : table.getRows()) {
for (XWPFTableCell cell : row.getTableCells()) {
for (XWPFParagraph paragraph : cell.getParagraphs()) {
for (XWPFRun run : paragraph.getRuns()) {
System.out.println("run text: " + run.text());
/** replace text here, etc. */
}
}
}
}
}
I want to extract the placeholders together with the enclosing ${ } characters. The problem is, that is seems like the enclosing characters are treated as different runs...
run text: ${
run text: programming_language
run text: }
run text: Some plain text here
run text: ${
run text: education
run text: }
Instead, I would like to achieve the following effect:
run text: ${programming_language}
run text: Some plain text here
run text: ${education}
I have tried using other enclosing characters, such as: { }, < >, # #, etc.
I do not want to do some weird concatenations of runs, etc. I want to have it in a single XWPFRun.
If I cannot find the proper solution, I will just make it like so: VAR_PROGRAMMING_LANGUGE, VAR_EDUCATION, I think.
Current apache poi 4.1.2 provides TextSegment to deal with those Word text-run issues. XWPFParagraph.searchText searches for a string in a paragraph and returns a TextSegment. This provides access to the begin run and the end run of that text in that paragraph (BeginRun and EndRun). It also provides access to the start character position in begin run and end character position in end run (BeginChar and EndChar).
It additionally provides access to the index of the text element in the text run (BeginText and EndText). This always should be 0, because default text runs only have one text element.
Having this, we can do the following:
Replace the found partial string in begin run by the replacement. To do so, get the text part which was before the searched string and concatenate the replacement to it. After that the begin run fully contains the replacement.
Delete all text runs between begin run and end run as they contain parts of the searched string which is not more needed.
Let remain only the text part after the searched string in end run.
Doing so we are able replacing text which is in multiple text runs.
Following example shows this.
import java.io.*;
import org.apache.poi.xwpf.usermodel.*;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
public class WordReplaceTextSegment {
static public void replaceTextSegment(XWPFParagraph paragraph, String textToFind, String replacement) {
TextSegment foundTextSegment = null;
PositionInParagraph startPos = new PositionInParagraph(0, 0, 0);
while((foundTextSegment = paragraph.searchText(textToFind, startPos)) != null) { // search all text segments having text to find
System.out.println(foundTextSegment.getBeginRun()+":"+foundTextSegment.getBeginText()+":"+foundTextSegment.getBeginChar());
System.out.println(foundTextSegment.getEndRun()+":"+foundTextSegment.getEndText()+":"+foundTextSegment.getEndChar());
// maybe there is text before textToFind in begin run
XWPFRun beginRun = paragraph.getRuns().get(foundTextSegment.getBeginRun());
String textInBeginRun = beginRun.getText(foundTextSegment.getBeginText());
String textBefore = textInBeginRun.substring(0, foundTextSegment.getBeginChar()); // we only need the text before
// maybe there is text after textToFind in end run
XWPFRun endRun = paragraph.getRuns().get(foundTextSegment.getEndRun());
String textInEndRun = endRun.getText(foundTextSegment.getEndText());
String textAfter = textInEndRun.substring(foundTextSegment.getEndChar() + 1); // we only need the text after
if (foundTextSegment.getEndRun() == foundTextSegment.getBeginRun()) {
textInBeginRun = textBefore + replacement + textAfter; // if we have only one run, we need the text before, then the replacement, then the text after in that run
} else {
textInBeginRun = textBefore + replacement; // else we need the text before followed by the replacement in begin run
endRun.setText(textAfter, foundTextSegment.getEndText()); // and the text after in end run
}
beginRun.setText(textInBeginRun, foundTextSegment.getBeginText());
// runs between begin run and end run needs to be removed
for (int runBetween = foundTextSegment.getEndRun() - 1; runBetween > foundTextSegment.getBeginRun(); runBetween--) {
paragraph.removeRun(runBetween); // remove not needed runs
}
}
}
public static void main(String[] args) throws Exception {
XWPFDocument doc = new XWPFDocument(new FileInputStream("source.docx"));
String textToFind = "${This is the text to find}"; // might be in different runs
String replacement = "Replacement text";
for (XWPFParagraph paragraph : doc.getParagraphs()) { //go through all paragraphs
if (paragraph.getText().contains(textToFind)) { // paragraph contains text to find
replaceTextSegment(paragraph, textToFind, replacement);
}
}
FileOutputStream out = new FileOutputStream("result.docx");
doc.write(out);
out.close();
doc.close();
}
}
Above code works not in all cases because XWPFParagraph.searchText has bugs. So I will provide a better searchText method:
/**
* this methods parse the paragraph and search for the string searched.
* If it finds the string, it will return true and the position of the String
* will be saved in the parameter startPos.
*
* #param searched
* #param startPos
*/
static TextSegment searchText(XWPFParagraph paragraph, String searched, PositionInParagraph startPos) {
int startRun = startPos.getRun(),
startText = startPos.getText(),
startChar = startPos.getChar();
int beginRunPos = 0, candCharPos = 0;
boolean newList = false;
//CTR[] rArray = paragraph.getRArray(); //This does not contain all runs. It lacks hyperlink runs for ex.
java.util.List<XWPFRun> runs = paragraph.getRuns();
int beginTextPos = 0, beginCharPos = 0; //must be outside the for loop
//for (int runPos = startRun; runPos < rArray.length; runPos++) {
for (int runPos = startRun; runPos < runs.size(); runPos++) {
//int beginTextPos = 0, beginCharPos = 0, textPos = 0, charPos; //int beginTextPos = 0, beginCharPos = 0 must be outside the for loop
int textPos = 0, charPos;
//CTR ctRun = rArray[runPos];
CTR ctRun = runs.get(runPos).getCTR();
XmlCursor c = ctRun.newCursor();
c.selectPath("./*");
try {
while (c.toNextSelection()) {
XmlObject o = c.getObject();
if (o instanceof CTText) {
if (textPos >= startText) {
String candidate = ((CTText) o).getStringValue();
if (runPos == startRun) {
charPos = startChar;
} else {
charPos = 0;
}
for (; charPos < candidate.length(); charPos++) {
if ((candidate.charAt(charPos) == searched.charAt(0)) && (candCharPos == 0)) {
beginTextPos = textPos;
beginCharPos = charPos;
beginRunPos = runPos;
newList = true;
}
if (candidate.charAt(charPos) == searched.charAt(candCharPos)) {
if (candCharPos + 1 < searched.length()) {
candCharPos++;
} else if (newList) {
TextSegment segment = new TextSegment();
segment.setBeginRun(beginRunPos);
segment.setBeginText(beginTextPos);
segment.setBeginChar(beginCharPos);
segment.setEndRun(runPos);
segment.setEndText(textPos);
segment.setEndChar(charPos);
return segment;
}
} else {
candCharPos = 0;
}
}
}
textPos++;
} else if (o instanceof CTProofErr) {
c.removeXml();
} else if (o instanceof CTRPr) {
//do nothing
} else {
candCharPos = 0;
}
}
} finally {
c.dispose();
}
}
return null;
}
This will be called like:
...
while((foundTextSegment = searchText(paragraph, textToFind, startPos)) != null) {
...
Just like someone has commented your question, you can't have control where or when Word will split the paragraph in some runs. If the other answer still didn't help you, then I have the way I got around it:
First of all, this "solution" have a big problem, but still, I will put it here for the reason that someone can solve it.
public void mainMethod(XWPFParagraph paragraph) {
if (paragraph.getRuns().size() > 1) {
String myRun = unifyRuns(paragraph.getRuns());
// make the verification of placeholders ${...}
paragraph.getRuns().get(0).setText(myRun);
while(paragraph.getRuns().size() > 1) {
paragraph.removeRun(1);
}
}
}
private String unifyRuns(List<XWPFRun> runElements) {
StringBuilder unifiedRun = new StringBuilder();
for (XWPFRun run : runElements) {
unifiedRun.append(run);
}
return unifiedRun.toString();
}
The code may contain some error since I'm doing it as I remember.
The problem here is that when Word separates paragraphs into runs, it doesn't do it for nothing, because when there are texts with different fonts (like font-family or font-size), it separates the texts in different runs.
In the text "Here's my bold text", Word will split the text to separate the bold and normal text. Then, the code above is a bad solution if you are using POI to create large documents with different types of fonts. In that case you would need to verify first if the run is actualy in bold, then you will treat the placeholders.
Again, this a "solution" that i found, and it's not complete yet. Sorry for english errors, i'm using Google Translate to write this answer.
I need to remove property in Text (setRise) , if t.setRise(+-) gets out of fields paper.
PdfDocument pdfDoc = new PdfDocument(pdfWriter);
Document doc = new Document(pdfDoc, PageSize.A5);
doc.setMargins(0,0,0,36);
for (int i = 0; i <50 ; i++) {
Text t = new Text("hello " + i);
if(i ==0){
t.setTextRise(7);
}
if(i==31){
t.setTextRise(-35);
}
Paragraph p = new Paragraph(t);
p.setNextRenderer(new ParagraphRen(p,doc));
p.setFixedLeading(fixedLeading);
doc.add(p);
}
doc.close();
}
class ParagraphRen extends ParagraphRenderer{
private float heightDoc;
private float marginTop;
private float marginBot;
public ParagraphRen(Paragraph modelElement, Document doc) {
super(modelElement);
this.heightDoc =doc.getPdfDocument().getDefaultPageSize().getHeight();
this.marginTop = doc.getTopMargin();
this.marginBot = doc.getBottomMargin();
}
#Override
public void drawChildren(DrawContext drawContext) {
super.drawChildren(drawContext);
Rectangle rect = this.getOccupiedAreaBBox();
List<IRenderer> childRenderers = this.getChildRenderers();
//check first line
if(rect.getTop()<=heightDoc- marginTop) {
for (IRenderer iRenderer : childRenderers) {
if (iRenderer.getModelElement().hasProperty(72)) {
Object property = iRenderer.getModelElement().getProperty(72);
float v = (Float) property + rect.getTop();
//check text more AreaPage
if(v >heightDoc){
iRenderer.getModelElement().deleteOwnProperty(72);
}
}
}
}
//check last line
if(rect.getBottom()-marginBot-rect.getHeight()*2<0){
for (IRenderer iRenderer : childRenderers) {
if (iRenderer.getModelElement().hasProperty(72)) {
Object property = iRenderer.getModelElement().getProperty(72);
//if setRise(-..) more margin bottom setRise remove
if(rect.getBottom()-marginBot-rect.getHeight()+(Float) property<0)
iRenderer.getModelElement().deleteOwnProperty(72);
}
}
}
}
}
Here i check if first lines with setRise more the paper area I remove setRise property.
And if last lines with serRise(-35) more then margin bottom I remove it.
But it doesn't work. Properties don't remove.
Your problem is as follows: drawChildren method gets called after rendering has been done. At this stage iText usually doesn't consider properties of any elements: it just places the element in its occupied area, which has been calculated before, at layout() stage.
You can overcome it with layout emulation.
Let's add all your paragraphs to a div rather than directly to the document. Then emulate adding this div to the document:
LayoutResult result = div.createRendererSubTree().setParent(doc.getRenderer()).layout(new LayoutContext(new LayoutArea(0, PageSize.A5)));
In the snippet above I've tried to layout our div on a A5-sized document.
Now you can consider the result of layout and change some elements, which will be then processed for real with Document#add. For example, to get the 30th layouted paragraph one can use:
((DivRenderer)result.getSplitRenderer()).getChildRenderers().get(30);
Some more tips:
split renderer represent the part of the content which iText can place on the area, overflow - the content which overflows.
I´m making a text editor in Java for training purposes. So, I´m using JTextPane to edit the text and setCharacterAttributes to highlight some words in the text. The code works partially, in the first line everything works, but then in the second line and forth the code stops to work. The code bellow shows my attempt to fix this bug:
private void changeColor(StyledDocument styledDocument)
{
String keywords[] = {"html", "body", "div", "teste"};
String texto = edtEditing.getText();
int startIndex;
int start;
StyleContext context = StyleContext.getDefaultStyleContext();
Style styleDefault = context.getStyle(StyleContext.DEFAULT_STYLE); // default
styledDocument.setCharacterAttributes(0, texto.length(), styleDefault, true);
AttributeSet attr = context.addAttribute(context.getEmptySet(), StyleConstants.Foreground, Color.red);
for (String word:keywords)
{
startIndex = 0;
start = texto.indexOf(word, startIndex);
while (start >= 0)
{
styledDocument.setCharacterAttributes(start, word.length(), attr, true);
startIndex += word.length();
start = texto.indexOf(word, startIndex);
}
}
}
See the error on the image bellow:
Click to see the error
The erros seems to occurs because of CRLF but I cannot figure out why...
Here is the executable jar file. Just select File->New and type "teste"
Thanks in advance!
This side-effect is caused by this line:
String texto = edtEditing.getText();
You're getting your text directly from the JTextPane, but you're setting your attributes on a StyledDocument object. Change this line to:
StyledDocument document = edtEditing.getStyledDocument();
String texto = document.getText(0, document.getLength());
And handle the possible exception.
You can run the code below to see that this behavior is consistent, and contrary to one might expect, a "false" will be printed.
JTextPane pane = new JTextPane();
pane.setText("Something html\r\nSomething html");
StyledDocument document = pane.getStyledDocument();
String text2 = pane.getText();
String text1 = document.getText(0, document.getLength());
System.out.println(text1.equals(text2));
I am in the process of adding some html based formatting features to a JTextPane. The idea is that the user would select text in the JTextPane, then click a button (bold, italic etc) to insert the html tags at the appropriate locations. I can do this without difficulty using the JTextPane.getSelectionStart() and .getSelectionEnd() methods.
My problem is that I also want to scan each character in the JTextPane to index all the html tag locations - this is so the software can detect where the JTextPane caret is in relation to the html tags. This information is then used if the user wants to remove the formatting tags.
I am having difficulty synchronising this character index with the caret position in the JTextPane. Here is the code I have been using:
public void scanHTML(){
try {
boolean blnDocStartFlag = false;
alTagRecords = new ArrayList(25);
alTextOnlyIndex = new ArrayList();
String strTagBuild = "";
int intTagIndex = 0; // The index for a tag pair record in alTagRecords.
int intTextOnlyCount = 0; // Counts each text character, ignoring all html tags.
// Loop through HTMLDoc character array:
for (int i = 0; i <= strHTMLDoc.length() -1; i ++){
// Look for the "<" angle bracket enclosing the tag keyword ...
if (strHTMLDoc.charAt(i) == '<'){// It is a html tag ...
int intTagStartLocation = i; // this value will go into alTagFields(?,0) later ...
while (strHTMLDoc.charAt(i) != '>'){
strTagBuild += strHTMLDoc.charAt(i);
i ++; // continue incrementing the iterator whilst in this sub loop ...
}
strTagBuild += '>'; // makes sure the closing tag is not missed from the string
if (!strTagBuild.startsWith("</")){
// Create new tag record:
ArrayList<Integer> alTagFields = new ArrayList(3);
alTagFields.add(0, intTagStartLocation); // Tag start location index ...
alTagFields.add(1, -1); // Tag end not known at this stage ...
alTagFields.add(2, getTagType(strTagBuild));
alTagRecords.add(intTagIndex, alTagFields); // Tag Type
System.out.println("Tag: " + strTagBuild);
intTagIndex ++; // Increment the tag records index ...
} else { // find corresponding start tag and store its location in the appropriate field of alTagFields:
int intManipulatedTagIndex = getMyOpeningTag(getTagType(strTagBuild));
ArrayList<Integer> alManipulateTagFields = alTagRecords.get(intManipulatedTagIndex);
alManipulateTagFields.set(1, (intTagStartLocation + strTagBuild.length() -1) ); // store the position of the end angled bracket of the closing tag ...
alTagRecords.set(intManipulatedTagIndex, alManipulateTagFields);
System.out.println("Tag: " + strTagBuild);
}
strTagBuild = "";
} else {
// Create the text index:
if (blnDocStartFlag == false){
int intAscii = (int) strHTMLDoc.charAt(i);
if (intAscii >= 33){ // Ascii character 33 is an exclamation mark(!). It is the first character after a space.
blnDocStartFlag = true;
}
}
// Has the first non space text character has been reached? ...
if (blnDocStartFlag == true){ // Index the character if it has ...
alTextOnlyIndex.add(i);
intTextOnlyCount ++;
}
}
}
} catch (Exception ex){
System.err.println("Error at HTMLTagIndexer.scanHTML: " + ex);
}
}
The problem with the code above is that the string variable strHTMLDoc is obtained using JTextPane.getText, and this appears to have inserted some extra space characters within the string. Consequently this has put it out of sync with the corresponding caret position in the text pane.
Can anybody suggest an alternative way to do what I am trying to achieve?
Many thanks