jeditorpane

JEditorPane and custom editor kit

醉酒当歌 提交于 2019-12-20 04:52:19
问题 I've a trivial question. I need to load an existing file into JEditorPane using custom editor kit. I've a editor kit, a file with some extension and I need to force the JEditorPane to recognize my file and use my editor kit. I've found only, that's possibile, but nowhere how. The kit is based on HTML and the file too. If file has the .html extension, it works, but when I rename the file to .xhtbm , it is opened as plain text. The content type is set to text/plain , but I'm unable to register

Is there a way to attatch a css file to a jEditorPane?

你说的曾经没有我的故事 提交于 2019-12-19 19:59:25
问题 Simple enough question: I have a string containing HTML that is being handed off to a JEditorPane for user consumption. Can I attach a CSS file (or string containing CSS rules) to allow for more specific styling of the text? 回答1: The HTMLEditorKit per default looks for a file default.css - I'm not sure where, though. Alternatively, this should work: StyleSheet ss = new StyleSheet(); ss.importStyleSheet(styleSheetURL); HTMLEditorKit kit = (HTMLEditorKit)jEditorPane.getEditorKit(); kit

Is there a way to attatch a css file to a jEditorPane?

 ̄綄美尐妖づ 提交于 2019-12-19 19:59:23
问题 Simple enough question: I have a string containing HTML that is being handed off to a JEditorPane for user consumption. Can I attach a CSS file (or string containing CSS rules) to allow for more specific styling of the text? 回答1: The HTMLEditorKit per default looks for a file default.css - I'm not sure where, though. Alternatively, this should work: StyleSheet ss = new StyleSheet(); ss.importStyleSheet(styleSheetURL); HTMLEditorKit kit = (HTMLEditorKit)jEditorPane.getEditorKit(); kit

showing images on jeditorpane (java swing)

狂风中的少年 提交于 2019-12-19 17:44:42
问题 I have a JEditorPane created by this way: JEditorPane pane = new JEditorPane("text/html", "<font face='Arial'>" + my_text_to_show + "<img src='/root/img.gif'/>" + "</font>"); I put this pane on a JFrame. Text is shown correctly, but I can't see the picture, there is only a square indicating that there should be an image (i.e.: "broken image" shown by browsers when picture has not been found) 回答1: You have to provide type, and get the resource. That's all. My tested example, but I'm not sure

JEditorPane Hyperlink swing html

时光总嘲笑我的痴心妄想 提交于 2019-12-19 11:24:58
问题 I'm having a difficult time getting the hyperlink to work in a JEditorPane. Could someone please tell me what I'm doing wrong here? I want to be able to click on the link and the browser to open to that page. Thanks in advance. :D bottomText.setText("<a href=\"http://www.yahoo.com\">Yahoo</a>"); bottomText.setEditable(false); bottomText.setOpaque(false); bottomText.setEditorKit(JEditorPane.createEditorKitForContentType("text/html")); bottomText.addHyperlinkListener(new HyperlinkListener() {

Getting the visible text in a JEditorPane

僤鯓⒐⒋嵵緔 提交于 2019-12-19 04:46:47
问题 I have a JeditorPane in a JScrollPane. At certain points in the application, I would like to retrieve the text that is visible in the scrollPane (the text that is currently showing) and only this text. Is there a way to do this? Thank you, Elliott 回答1: You can use the viewport to get the view position and size. JViewport viewport = scrollPane.getViewport(); Point startPoint = viewport.getViewPosition(); Dimension size = viewport.getExtentSize(); Point endPoint = new Point(startPoint.x + size

jEditorPane as a web browser

孤街浪徒 提交于 2019-12-18 04:48:09
问题 I am creating a web browser in Java. In this browser I am using JEditorPane for Browser Window. I am using "setPage(String url)" method to display the page. The browser can display the page but there are some problems which are as mentioned:: The browser is not displaying the java script. It is not displaying the Applet. Brows data does not show in proper way(like as a browser(Show in image )). My code is- JEditorPane editorPane = new JEditorPane(); String url="http://google.co.in";

Show HTML file in JEditorPane

送分小仙女□ 提交于 2019-12-17 17:01:00
问题 I am working on a Swing application in which I have to show HTML files. I am using JEditorPane control for it. It is showing the content of HTML file but not in the same format as originally in the actual HTML file. JEditorPane does not support the object element. Rather than loading the object file its just showing ? . Is there any other inbuilt control in Swing to browse the HTML file rather than JEditorPane ? I am using the following code: JEditorPane HtmlPane= new JEditorPane(); File

JEditorPane with inline image

社会主义新天地 提交于 2019-12-17 07:48:24
问题 I'm attempting to display an inline image in a Java JEditorPane. The code below uses HTML content that properly displays the image in Firefox, but not in the JEditorPane. Any ideas why? Thanks. import javax.swing.*; import java.awt.*; public class InlineImage { public InlineImage() { JFrame frame=new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JEditorPane edit=new JEditorPane(); frame.getContentPane().add(edit); edit.setContentType("text/html"); String html = "<html><body

Highlight a word in JEditorPane

若如初见. 提交于 2019-12-17 06:54:49
问题 I have to highlight the all occurrences of a word in JEditorPane . For this I am using the following code: try { javax.swing.text.DefaultHighlighter.DefaultHighlightPainter highlightPainter = new javax.swing.text.DefaultHighlighter.DefaultHighlightPainter(Color.YELLOW); textPane.getHighlighter().addHighlight(startPos, endPos, highlightPainter); } catch(Exception ex) { } But how can I give the position of index of a word? I am reading the content from file but it is reading the HTML tags also