G
Gerrit Hulleman
Is it possible ot insert a span tag in the editorpane?
Using the code:
HTMLDocument doc = (HTMLDocument) htmledit.getEditor().getDocument();
HTMLEditorKit kit = (HTMLEditorKit) htmledit.getEditor().getEditorKit();
int start = htmledit.getEditor().getSelectionStart();
int end = htmledit.getEditor().getSelectionEnd();
The following does not work:
kit.insertHTML(doc, start, "<span
class=\""+fontfamily+"\">"+htmledit.getEditor().getSelectedText()+"</span>",
0, 0, HTML.Tag.DIV);
--> does not add a thing, does work for a div tag
kit.insertHTML(doc, start, "<span></span>", 0, 0, HTML.Tag.SPAN);
--> add only a </span>, does work for a div tag
doc.insertString(start, "<span
class=\""+fontfamily+"\">"+htmledit.getEditor().getSelectedText()+"</span>",
null); (thought it was worth a try)
--> offcourse, adds this as text (with replacements: "<" => "<")
or
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
kit.write(buffer, doc, 0, start);
String newtext = buffer.toString();
System.out.println(newtext);
........
--> this code copies the text till the start of the selection, but
adds closing tags ( >< )
Is it at all possible to insert span tags? Perhaps it is possible to add
tags usingthe kit.insertHTML without telling it what kind of tag it is...
Gerrit
Using the code:
HTMLDocument doc = (HTMLDocument) htmledit.getEditor().getDocument();
HTMLEditorKit kit = (HTMLEditorKit) htmledit.getEditor().getEditorKit();
int start = htmledit.getEditor().getSelectionStart();
int end = htmledit.getEditor().getSelectionEnd();
The following does not work:
kit.insertHTML(doc, start, "<span
class=\""+fontfamily+"\">"+htmledit.getEditor().getSelectedText()+"</span>",
0, 0, HTML.Tag.DIV);
--> does not add a thing, does work for a div tag
kit.insertHTML(doc, start, "<span></span>", 0, 0, HTML.Tag.SPAN);
--> add only a </span>, does work for a div tag
doc.insertString(start, "<span
class=\""+fontfamily+"\">"+htmledit.getEditor().getSelectedText()+"</span>",
null); (thought it was worth a try)
--> offcourse, adds this as text (with replacements: "<" => "<")
or
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
kit.write(buffer, doc, 0, start);
String newtext = buffer.toString();
System.out.println(newtext);
........
--> this code copies the text till the start of the selection, but
adds closing tags ( >< )
Is it at all possible to insert span tags? Perhaps it is possible to add
tags usingthe kit.insertHTML without telling it what kind of tag it is...
Gerrit