javax.swing.text.html.HTMLEditorKit.insertHTML()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(122)

本文整理了Java中javax.swing.text.html.HTMLEditorKit.insertHTML()方法的一些代码示例,展示了HTMLEditorKit.insertHTML()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HTMLEditorKit.insertHTML()方法的具体详情如下:
包路径:javax.swing.text.html.HTMLEditorKit
类名称:HTMLEditorKit
方法名:insertHTML

HTMLEditorKit.insertHTML介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

  1. JTextPane text_panel = new JTextPane();
  2. HTMLEditorKit kit = new HTMLEditorKit();
  3. HTMLDocument doc = new HTMLDocument();
  4. text_panel.setEditorKit(kit);
  5. text_panel.setDocument(doc);
  6. kit.insertHTML(doc, doc.getLength(), "<b>hello", 0, 0, HTML.Tag.B);
  7. kit.insertHTML(doc, doc.getLength(), "<font color='red'><u>world</u></font>", 0, 0, null);

代码示例来源:origin: magefree/mage

  1. public void append(String text) {
  2. try {
  3. if (hyperlinkEnabled) {
  4. text = text.replaceAll("(<font color=[^>]*>([^<]*)) (\\[[0-9a-fA-F]*\\])</font>", "<a href=\"#$2\">$1</a> $3");
  5. }
  6. kit.insertHTML(doc, doc.getLength(), text, 0, 0, null);
  7. int len = getDocument().getLength();
  8. setCaretPosition(len);
  9. } catch (Exception e) {
  10. e.printStackTrace();
  11. }
  12. }

代码示例来源:origin: stackoverflow.com

  1. Component c = getFocusOwner();
  2. if(c==html){
  3. HTMLEditorKit kit = (HTMLEditorKit) html.getEditorKit();
  4. HTMLDocument doc = (HTMLDocument) html.getStyledDocument();
  5. kit.insertHTML(doc, html.getCaretPosition(), builder.toString(), 0, 0, null);
  6. }else if(c==text){
  7. text.getStyledDocument().insertString(text.getCaretPosition(), builder.toString(), null);
  8. }

代码示例来源:origin: stackoverflow.com

  1. HTMLEditorKit kit = (HTMLEditorKit) html.getEditorKit();
  2. HTMLDocument doc = (HTMLDocument) html.getStyledDocument();
  3. kit.insertHTML(doc, html.getCaretPosition(), builder.toString(), 0, 0, null);

代码示例来源:origin: stackoverflow.com

  1. HTMLEditorKit editorKit = (HTMLEditorKit)textPane.getEditorKit();
  2. text = "<a href=\"abc\">hyperlink</a>";
  3. editorKit.insertHTML(doc, textPane.getCaretPosition(), text, 0, 0, HTML.Tag.A);

代码示例来源:origin: stackoverflow.com

  1. HTMLDocument doc = (HTMLDocument)textPane.getDocument();
  2. HTMLEditorKit editorKit = (HTMLEditorKit)textPane.getEditorKit();
  3. String text = "<a href=\"abc\">hyperlink</a>";
  4. editorKit.insertHTML(doc, doc.getLength(), text, 0, 0, null);

代码示例来源:origin: stackoverflow.com

  1. HTMLEditorKit editorKit = (HTMLEditorKit)textPane.getEditorKit();
  2. HTMLDocument doc = (HTMLDocument)textPane.getDocument();
  3. String text = "<a href=\"abc\">hyperlink</a>";
  4. editorKit.insertHTML(doc, doc.getLength(), text, 0, 0, null);

代码示例来源:origin: stackoverflow.com

  1. HTMLDocument document = (HTMLDocument)textPane.getDocument();
  2. HTMLEditorKit editorKit = (HTMLEditorKit)textPane.getEditorKit();
  3. String text = "your HTML here";
  4. editorKit.insertHTML(document, document.getLength(), text, 0, 0, null);

代码示例来源:origin: stackoverflow.com

  1. public void Imagen(){
  2. int im = ImageChooser.showOpenDialog(ImageChooser);
  3. if (im == JFileChooser.APPROVE_OPTION){
  4. System.out.println("Loading Image...");
  5. int caretPos = EditorPane.getCaretPosition();
  6. HTMLEditorKit e = new HTMLEditorKit();
  7. try {
  8. String Path = String.format( ImageChooser.getSelectedFile().getAbsolutePath());
  9. System.out.println(Path);
  10. e.insertHTML(document, caretPos,"<img src=\"file:\\"+Path+"\" alt=\"some_text\">" , 0, 0, HTML.Tag.IMG);
  11. // <img src="url" alt="some_text">
  12. } catch (BadLocationException ex) {
  13. Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
  14. } catch (IOException ex) {
  15. Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
  16. }
  17. }else{
  18. System.out.println("Nothing loaded");}
  19. }

代码示例来源:origin: stackoverflow.com

  1. HTMLDocument doc = new HTMLDocument();
  2. HTMLEditorKit kit = new HTMLEditorKit();
  3. jEditorPane.setDocument(doc);
  4. jEditorPane.setEditorKit(kit);
  5. kit.insertHTML(doc, doc.getLength(), "<label> This label will be inserted inside the body directly </label>", 0, 0, null);
  6. kit.insertHTML(doc, doc.getLength(), "<br/>", 0, 0, null);
  7. kit.insertHTML(doc, doc.getLength(), putYourVariableHere, 0, 0, null);

代码示例来源:origin: MarginallyClever/Makelangelo-software

  1. public void clearLog() {
  2. try {
  3. doc.replace(0, doc.getLength(), "", null);
  4. kit.insertHTML(doc, 0, "", 0, 0, null);
  5. //logPane.getVerticalScrollBar().setValue(logPane.getVerticalScrollBar().getMaximum());
  6. } catch (BadLocationException | IOException e) {
  7. }
  8. }

代码示例来源:origin: stackoverflow.com

  1. pane = new JTextPane();
  2. jPanel1.add(pane);
  3. final HTMLEditorKit kit = new HTMLEditorKit();
  4. final HTMLDocument doc = new HTMLDocument();
  5. pane.setEditorKit(kit);
  6. pane.setDocument(doc);
  7. ...
  8. btnAdd.addActionListener(new ActionListener(){
  9. @Override public void actionPerformed(ActionEvent arg0) {
  10. int start = pane.getSelectionStart();
  11. try {
  12. // add a span containing the desired element inside the current paragraph or other containing element
  13. kit.insertHTML(doc, start, "<span>&cent;</span>", 0, 0, HTML.Tag.SPAN);
  14. } catch ...
  15. pane.grabFocus();
  16. }
  17. });

代码示例来源:origin: stackoverflow.com

  1. JTextPane textPane = new JTextPane();
  2. textPane.setContentType( "text/html" );
  3. textPane.setEditable(false);
  4. HTMLDocument doc = (HTMLDocument)textPane.getDocument();
  5. HTMLEditorKit editorKit = (HTMLEditorKit)textPane.getEditorKit();
  6. String text = "<a href=\"abc\">hyperlink</a>";
  7. editorKit.insertHTML(doc, doc.getLength(), text, 0, 0, null);

代码示例来源:origin: stackoverflow.com

  1. HTMLEditorKit kit = new HTMLEditorKit();
  2. HTMLDocument doc = new HTMLDocument();
  3. ...
  4. logTextPane.setEditorKit(kit);
  5. logTextPane.setDocument(doc);
  6. public void onLogData(final String message) {
  7. SwingUtilities.invokeLater(new Runnable() {
  8. @Override
  9. public void run() {
  10. try {
  11. kit.insertHTML(doc, doc.getLength(), message, 0, 0, null);
  12. } catch (BadLocationException ex) {
  13. Logger.getLogger(SummaryPanel.class.getName()).log(Level.SEVERE, null, ex);
  14. } catch (IOException ex) {
  15. Logger.getLogger(SummaryPanel.class.getName()).log(Level.SEVERE, null, ex);
  16. }
  17. }
  18. });
  19. }

代码示例来源:origin: stackoverflow.com

  1. JTextPane textPane = new JTextPane();
  2. JButton button = new JButton("Button");
  3. button.setAlignmentY(0.85f);
  4. HTMLEditorKit kit = new HTMLEditorKit();
  5. HTMLDocument doc = new HTMLDocument();
  6. textPane.setEditorKit(kit);
  7. textPane.setDocument(doc);
  8. try {
  9. kit.insertHTML(doc, doc.getLength(), "<p color='#FF0000'>Cool!", 0, 0, HTML.Tag.P);
  10. kit.insertHTML(doc, doc.getLength(), "<p></p>", 0, 0, null);
  11. } catch (BadLocationException ex) {
  12. } catch (IOException ex) {
  13. }

代码示例来源:origin: stackoverflow.com

  1. editorKit.insertHTML(doc, doc.getLength(), "<a href=\"http://click.com\">clickable1</a>", 0, 0, null);
  2. editorKit.insertHTML(doc, doc.getLength(), "<a href=\"c2\">clickable2</a>", 0, 0, null);
  3. editorKit.insertHTML(doc, doc.getLength(), "<a href=\"c3\">clickable3</a>", 0, 0, null);
  4. } catch (BadLocationException | IOException e) {
  5. e.printStackTrace();

代码示例来源:origin: MarginallyClever/Makelangelo-software

  1. @Override
  2. public void publish(LogRecord record) {
  3. // TODO Auto-generated method stub
  4. if (!isLoggable(record))
  5. return;
  6. String message = getFormatter().format(record);
  7. try {
  8. kit.insertHTML(doc, doc.getLength(), message, 0, 0, null);
  9. } catch (BadLocationException | IOException e) {
  10. // TODO Auto-generated catch block
  11. e.printStackTrace();
  12. }
  13. logArea.validate();
  14. }

代码示例来源:origin: org.scijava/scijava-ui-swing

  1. /** Appends the given HTML text string to the text pane. Efficient. */
  2. public void append(final String text) {
  3. try {
  4. kit.insertHTML(doc, doc.getLength(), text, 0, 0, null);
  5. }
  6. catch (final BadLocationException e) {
  7. log.error(e);
  8. }
  9. catch (final IOException e) {
  10. log.error(e);
  11. }
  12. scrollToBottom();
  13. }

代码示例来源:origin: MarginallyClever/Makelangelo-software

  1. long caretPosition = logArea.getCaretPosition();
  2. kit.insertHTML(doc, doc.getLength(), msg, 0, 0, null);

代码示例来源:origin: Jamling/SmartIM

  1. @Override
  2. public void run() {
  3. try {
  4. HTMLEditorKit kit = (HTMLEditorKit) historyWidget
  5. .getEditorKit();
  6. HTMLDocument doc = (HTMLDocument) historyWidget
  7. .getDocument();
  8. // historyWidget.getDocument().insertString(len - offset,
  9. // trimMsg(msg), null);
  10. // Element root = doc.getDefaultRootElement();
  11. // Element body = root.getElement(1);
  12. // doc.insertBeforeEnd(body, msg);
  13. int pos = historyWidget.getCaretPosition();
  14. kit.insertHTML(doc, doc.getLength(), msg, 0, 0, null);
  15. historyWidget.setCaretPosition(
  16. scrollLock ? pos : doc.getLength());
  17. } catch (Exception e) {
  18. e.printStackTrace();
  19. }
  20. }
  21. });

相关文章