htmleditorkit

Using HTMLEditorKit in Java, how do I find what local file path <img src=…> tags will use?

为君一笑 提交于 2020-04-30 07:03:30
问题 I've got a java app running, and I'm using the HTMLDocument/HTMLEditorKit functionality to build my chat room. So far with plenty of success as far as building my stylesheet, inserting text messages, and so forth. So now I've come to... images! I had thought that if I were adding tags such as: <img src="myimage.png"> ... that my file then just needed to be in the same directory as the java app when I ran it. But I've run through all sorts of things and tried subdirectories, and it can't seem

How to get current html element(tag) in JTextPane?

微笑、不失礼 提交于 2020-01-05 04:33:33
问题 I am doing on WYSIWYG Html Editor using Java Program. I need When I click mouse on Paragraph element, It should be displays tag in JOption dialog. Please advice me How can i do this? 回答1: See for example this one http://java-sl.com/JEditorPaneStructureTool.html In simple words you can get your HTMLDocument and get paragraph using getParagraphElement() method. Use viewToModel() method of JEditorPane to get caret offet for the clicked point. 来源: https://stackoverflow.com/questions/10533940/how

How to provide Functionalty for Changing the Background Color of Text Parts in HTML Editor built with HTMLEditorKit

泪湿孤枕 提交于 2019-12-24 00:56:26
问题 My problem is as follows: I want to enable the user of my little HTML editor to switch between different background colors for the text being entered. I first tried to use CSS styles for that purpose. The different styles define different background colors and through a JComboBox the user could switch between these styles. Upon selection of a style in the respective position inside the HTMLDocument a new HTML element of type <span class="style"> would be entered. Unfortunately I could not

Convert HTML to plain text in Java

流过昼夜 提交于 2019-12-21 09:13:56
问题 I need to convert HTML to plain text. My only requirement of formatting is to retain new lines in the plain text. New lines should be displayed not only in the case of <br> but other tags, e.g. <tr/> , </p> leads to a new line too. Sample HTML pages for testing are: http://www.particle.kth.se/~lindsey/JavaCourse/Book/Part1/Java/Chapter09/scannerConsole.html http://www.javadb.com/write-to-file-using-bufferedwriter Note that these are only random URLs. I have tried out various libraries (JSoup,

Java Swing CSS style attribute “class” use in HTMLEditorKit/HTMLDocument

无人久伴 提交于 2019-12-13 21:27:40
问题 my problem is as follows: I'm trying to add functionality to an HTML editor which is implemented in Java Swing using HTMLEditorKit and HTMLDocument classes. The idea is to provide a possibility to switch between different styles during editing of the text in the HTML editor. The different styles define background/foreground colors, fonts and the like. I already managed to load a stylesheet file programmatically. The code for that looks as follows: class HtmlEditor extends JFrame implements

How to add to existing HTML in Jtextpane

自闭症网瘾萝莉.ら 提交于 2019-12-13 03:54:55
问题 I am making a chat program in Java/Swing, and the text is rendered in a Jtextpane object. Right now, a new message erases the old one, as I couldn't figure out how to add to the existing document. How to do this? public void addMessage(String sender, String msg) throws BadLocationException, IOException{ HTMLEditorKit kit = new HTMLEditorKit(); HTMLDocument doc = new HTMLDocument(); pane.setEditorKit(kit); pane.setDocument(doc); kit.insertHTML(doc, doc.getLength(), "<b>[" + sender + "]</b> " +

HTMLEditorKit and Custom tags in the JEditorPane

我们两清 提交于 2019-12-12 02:29:55
问题 I use the instructions to add my own tag http://java-sl.com/custom_tag_html_kit.html class MyParserDelegator extends ParserDelegator { public MyParserDelegator() { try { Field f=javax.swing.text.html.parser.ParserDelegator.class.getDeclaredField("dtd"); f.setAccessible(true); DTD dtd=(DTD)f.get(null); javax.swing.text.html.parser.Element div=dtd.getElement("div"); dtd.defineElement("button", div.getType(), true, true,div.getContent(),null, null,div.getAttributes()); } catch

Setting the font and style of jeditorpane

陌路散爱 提交于 2019-12-11 19:47:41
问题 I am currently developing an application for this company as my last year of studies project, and in this application there's this function that allows you to print a paper, so i used the jeditorpane obviously, with the Charles Bell HTMLEditorKit for the predefined functions like setting the font and printing, etc... and there's this pre-written text that i have to load from a text file and then the program is supposed to add some text inside the file automatically, and the user also is

How to open HTML file having another extension in JTextPane

守給你的承諾、 提交于 2019-12-11 07:39:49
问题 I have a HTML file and I need to display it in JTextPane . editor.setPage("file:///" + new File("test-resources/test.html").getAbsoluteFile()); This works properly. It uses my modified HTML editor kit and displays special tags as needed. But modified file is not exactly HTML. It should have another extension. But that's a problem. editor.setPage("file:///" + new File("test-resources/test.xhtbm").getAbsoluteFile()); The file has been just renamed and is being displayed as plain text now. Is

how to retrieve TITLE of a HTML with the help of HTMLEditorKit

巧了我就是萌 提交于 2019-12-07 17:28:02
问题 I want to retrieve TITLE attribute with the help of java's HTMLEditorKit ? this what I've written but it will return "null" all the time and inspector in eclipse doesn't help that much ! import java.io.FileReader; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.net.URL; import javax.swing.text.MutableAttributeSet; import javax.swing.text.html.HTML; import javax.swing.text.html.HTMLEditorKit; import javax.swing.text.html.parser.ParserDelegator;