本文整理了Java中javax.swing.text.html.HTMLEditorKit.insertHTML()
方法的一些代码示例,展示了HTMLEditorKit.insertHTML()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HTMLEditorKit.insertHTML()
方法的具体详情如下:
包路径:javax.swing.text.html.HTMLEditorKit
类名称:HTMLEditorKit
方法名:insertHTML
暂无
代码示例来源:origin: stackoverflow.com
JTextPane text_panel = new JTextPane();
HTMLEditorKit kit = new HTMLEditorKit();
HTMLDocument doc = new HTMLDocument();
text_panel.setEditorKit(kit);
text_panel.setDocument(doc);
kit.insertHTML(doc, doc.getLength(), "<b>hello", 0, 0, HTML.Tag.B);
kit.insertHTML(doc, doc.getLength(), "<font color='red'><u>world</u></font>", 0, 0, null);
代码示例来源:origin: magefree/mage
public void append(String text) {
try {
if (hyperlinkEnabled) {
text = text.replaceAll("(<font color=[^>]*>([^<]*)) (\\[[0-9a-fA-F]*\\])</font>", "<a href=\"#$2\">$1</a> $3");
}
kit.insertHTML(doc, doc.getLength(), text, 0, 0, null);
int len = getDocument().getLength();
setCaretPosition(len);
} catch (Exception e) {
e.printStackTrace();
}
}
代码示例来源:origin: stackoverflow.com
Component c = getFocusOwner();
if(c==html){
HTMLEditorKit kit = (HTMLEditorKit) html.getEditorKit();
HTMLDocument doc = (HTMLDocument) html.getStyledDocument();
kit.insertHTML(doc, html.getCaretPosition(), builder.toString(), 0, 0, null);
}else if(c==text){
text.getStyledDocument().insertString(text.getCaretPosition(), builder.toString(), null);
}
代码示例来源:origin: stackoverflow.com
HTMLEditorKit kit = (HTMLEditorKit) html.getEditorKit();
HTMLDocument doc = (HTMLDocument) html.getStyledDocument();
kit.insertHTML(doc, html.getCaretPosition(), builder.toString(), 0, 0, null);
代码示例来源:origin: stackoverflow.com
HTMLEditorKit editorKit = (HTMLEditorKit)textPane.getEditorKit();
text = "<a href=\"abc\">hyperlink</a>";
editorKit.insertHTML(doc, textPane.getCaretPosition(), text, 0, 0, HTML.Tag.A);
代码示例来源:origin: stackoverflow.com
HTMLDocument doc = (HTMLDocument)textPane.getDocument();
HTMLEditorKit editorKit = (HTMLEditorKit)textPane.getEditorKit();
String text = "<a href=\"abc\">hyperlink</a>";
editorKit.insertHTML(doc, doc.getLength(), text, 0, 0, null);
代码示例来源:origin: stackoverflow.com
HTMLEditorKit editorKit = (HTMLEditorKit)textPane.getEditorKit();
HTMLDocument doc = (HTMLDocument)textPane.getDocument();
String text = "<a href=\"abc\">hyperlink</a>";
editorKit.insertHTML(doc, doc.getLength(), text, 0, 0, null);
代码示例来源:origin: stackoverflow.com
HTMLDocument document = (HTMLDocument)textPane.getDocument();
HTMLEditorKit editorKit = (HTMLEditorKit)textPane.getEditorKit();
String text = "your HTML here";
editorKit.insertHTML(document, document.getLength(), text, 0, 0, null);
代码示例来源:origin: stackoverflow.com
public void Imagen(){
int im = ImageChooser.showOpenDialog(ImageChooser);
if (im == JFileChooser.APPROVE_OPTION){
System.out.println("Loading Image...");
int caretPos = EditorPane.getCaretPosition();
HTMLEditorKit e = new HTMLEditorKit();
try {
String Path = String.format( ImageChooser.getSelectedFile().getAbsolutePath());
System.out.println(Path);
e.insertHTML(document, caretPos,"<img src=\"file:\\"+Path+"\" alt=\"some_text\">" , 0, 0, HTML.Tag.IMG);
// <img src="url" alt="some_text">
} catch (BadLocationException ex) {
Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
}
}else{
System.out.println("Nothing loaded");}
}
代码示例来源:origin: stackoverflow.com
HTMLDocument doc = new HTMLDocument();
HTMLEditorKit kit = new HTMLEditorKit();
jEditorPane.setDocument(doc);
jEditorPane.setEditorKit(kit);
kit.insertHTML(doc, doc.getLength(), "<label> This label will be inserted inside the body directly </label>", 0, 0, null);
kit.insertHTML(doc, doc.getLength(), "<br/>", 0, 0, null);
kit.insertHTML(doc, doc.getLength(), putYourVariableHere, 0, 0, null);
代码示例来源:origin: MarginallyClever/Makelangelo-software
public void clearLog() {
try {
doc.replace(0, doc.getLength(), "", null);
kit.insertHTML(doc, 0, "", 0, 0, null);
//logPane.getVerticalScrollBar().setValue(logPane.getVerticalScrollBar().getMaximum());
} catch (BadLocationException | IOException e) {
}
}
代码示例来源:origin: stackoverflow.com
pane = new JTextPane();
jPanel1.add(pane);
final HTMLEditorKit kit = new HTMLEditorKit();
final HTMLDocument doc = new HTMLDocument();
pane.setEditorKit(kit);
pane.setDocument(doc);
...
btnAdd.addActionListener(new ActionListener(){
@Override public void actionPerformed(ActionEvent arg0) {
int start = pane.getSelectionStart();
try {
// add a span containing the desired element inside the current paragraph or other containing element
kit.insertHTML(doc, start, "<span>¢</span>", 0, 0, HTML.Tag.SPAN);
} catch ...
pane.grabFocus();
}
});
代码示例来源:origin: stackoverflow.com
JTextPane textPane = new JTextPane();
textPane.setContentType( "text/html" );
textPane.setEditable(false);
HTMLDocument doc = (HTMLDocument)textPane.getDocument();
HTMLEditorKit editorKit = (HTMLEditorKit)textPane.getEditorKit();
String text = "<a href=\"abc\">hyperlink</a>";
editorKit.insertHTML(doc, doc.getLength(), text, 0, 0, null);
代码示例来源:origin: stackoverflow.com
HTMLEditorKit kit = new HTMLEditorKit();
HTMLDocument doc = new HTMLDocument();
...
logTextPane.setEditorKit(kit);
logTextPane.setDocument(doc);
public void onLogData(final String message) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
kit.insertHTML(doc, doc.getLength(), message, 0, 0, null);
} catch (BadLocationException ex) {
Logger.getLogger(SummaryPanel.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(SummaryPanel.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
}
代码示例来源:origin: stackoverflow.com
JTextPane textPane = new JTextPane();
JButton button = new JButton("Button");
button.setAlignmentY(0.85f);
HTMLEditorKit kit = new HTMLEditorKit();
HTMLDocument doc = new HTMLDocument();
textPane.setEditorKit(kit);
textPane.setDocument(doc);
try {
kit.insertHTML(doc, doc.getLength(), "<p color='#FF0000'>Cool!", 0, 0, HTML.Tag.P);
kit.insertHTML(doc, doc.getLength(), "<p></p>", 0, 0, null);
} catch (BadLocationException ex) {
} catch (IOException ex) {
}
代码示例来源:origin: stackoverflow.com
editorKit.insertHTML(doc, doc.getLength(), "<a href=\"http://click.com\">clickable1</a>", 0, 0, null);
editorKit.insertHTML(doc, doc.getLength(), "<a href=\"c2\">clickable2</a>", 0, 0, null);
editorKit.insertHTML(doc, doc.getLength(), "<a href=\"c3\">clickable3</a>", 0, 0, null);
} catch (BadLocationException | IOException e) {
e.printStackTrace();
代码示例来源:origin: MarginallyClever/Makelangelo-software
@Override
public void publish(LogRecord record) {
// TODO Auto-generated method stub
if (!isLoggable(record))
return;
String message = getFormatter().format(record);
try {
kit.insertHTML(doc, doc.getLength(), message, 0, 0, null);
} catch (BadLocationException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
logArea.validate();
}
代码示例来源:origin: org.scijava/scijava-ui-swing
/** Appends the given HTML text string to the text pane. Efficient. */
public void append(final String text) {
try {
kit.insertHTML(doc, doc.getLength(), text, 0, 0, null);
}
catch (final BadLocationException e) {
log.error(e);
}
catch (final IOException e) {
log.error(e);
}
scrollToBottom();
}
代码示例来源:origin: MarginallyClever/Makelangelo-software
long caretPosition = logArea.getCaretPosition();
kit.insertHTML(doc, doc.getLength(), msg, 0, 0, null);
代码示例来源:origin: Jamling/SmartIM
@Override
public void run() {
try {
HTMLEditorKit kit = (HTMLEditorKit) historyWidget
.getEditorKit();
HTMLDocument doc = (HTMLDocument) historyWidget
.getDocument();
// historyWidget.getDocument().insertString(len - offset,
// trimMsg(msg), null);
// Element root = doc.getDefaultRootElement();
// Element body = root.getElement(1);
// doc.insertBeforeEnd(body, msg);
int pos = historyWidget.getCaretPosition();
kit.insertHTML(doc, doc.getLength(), msg, 0, 0, null);
historyWidget.setCaretPosition(
scrollLock ? pos : doc.getLength());
} catch (Exception e) {
e.printStackTrace();
}
}
});
内容来源于网络,如有侵权,请联系作者删除!