jeditorpane

How to trigger a hyperlink using a keystroke in a Swing JEditorPane

蓝咒 提交于 2019-12-11 14:29:19
问题 I'm trying to fire hyperlinks in a JEditorPane using the "Enter" keystroke. So that the hyperlink (if any) under the caret will fire rather than having to click with the mouse. Any help would be appreciated. 回答1: First of all the HyperlinkEvent is only fired on a non-editable JEditorPane so it will be difficult for the users to know when the caret is over a link. But if you do want to do this, then you should be using Key Bindings (not a KeyListener) to bind an Action to the ENTER KeyStroke.

How can I display an HTML file as a web page?

时光怂恿深爱的人放手 提交于 2019-12-11 12:09:12
问题 My code reads an HTML file and I want to show it in new frame as a web page. But I don't know - how can I do this? This is my code: public class EditorPaneLoad extends JFrame{ public EditorPaneLoad() throws Exception{ FileReader reader = new FileReader("a.html"); JEditorPane editor = new JEditorPane(); JTextPane editor = new JTextPane(); editor.setContentType( "text/html" ); editor.setEditable( false ); editor.read(reader, null); //System.out.println(editor.getText()); //System.out.println("

JEditorPane vertical aligment

感情迁移 提交于 2019-12-11 11:09:31
问题 I try to apply center vertical aligment to text in JEditorPane. But text still is aligned to the top. Where did I mistake? JEditorPane editor = new JEditorPane(); editor.setText("..large text block.."); editor.setAlignmentY(JEditorPane.CENTER_ALIGNMENT); // DOESN'T WORK JFrame frame = new JFrame(); frame.setSize(600, 400); frame.setVisible(true); frame.add(editor); 回答1: I find it is always best to do any special alignment by placing your components in a JPanel and then smartly choosing the

JScrollPane does not update its scroll to go down to follow the caret position because of Image in JEditorPane

安稳与你 提交于 2019-12-11 07:40:33
问题 I have a JTabbedPane which two tabs including two JScrollPane . Each JScrollPane is including a JEditorPane . If there is no image in the editor, there is no problem. When there is an image, the scroll does not go down to follow the caret position for the first editor, it's like the image gains always the caret beside it after loading at the end of loading the editor.. Here is my code: public class CaretPositionForJEditorPane { JTabbedPane tabs; JScrollPane scrollPane1; JEditorPane editor1;

Java JEditorPane not displaying images

a 夏天 提交于 2019-12-11 04:39:22
问题 I am unable to get a JEditorPane to render an HTML img tag as an image. All that is displayed is a placeholder graphic. Below is my code. Thanks in advance. What I see: My code: import java.awt.*; import java.io.File; import java.net.URL; import java.util.Hashtable; import javax.swing.*; import javax.swing.text.html.HTMLEditorKit; public class test { private static Hashtable image_cache; public static void main(String[] args) { image_cache = new Hashtable(); URL img_url = null; try { img_url

Fixing the size of JEditorPane Content

左心房为你撑大大i 提交于 2019-12-11 00:01:07
问题 I am trying to display a JEditorPane inside a JFrame (fixed size) which then displays a string of HTML text. I can get everything displaying, though it seems that the text inside the HTML string I pass into my EditorPane doesn't cut off and wrap to a new line. i.e it just extends off the screen. It seems that the setSize method has no bearing on the size of the Pane? I am making this app for different size screen so it is important that the text wraps to new lines and fits the screen size

caret position into the html of JEditorPane

不问归期 提交于 2019-12-10 18:53:45
问题 The getCaretPosition method of JEditorPane gives an index into the text only part of the html control. Is there a possibility to get the index into the html text? To be more specific suppose I have a html text (where | denotes the caret position) abcd<img src="1.jpg"/>123|<img src="2.jpg"/> Now getCaretPosition gives 8 while I would need 25 as a result to read out the filename of the image. 回答1: The underlying model of the JEditorPane (some subclass of StyledDocument, in your case

Formatting JEditorPane's cursor, tooltips, links

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 18:05:01
问题 Right now, I'm using Java Swing to create a JEditorPane primarily for its ability to have hyperlinks. I've successfully been able to display links and have them execute behavior upon a click, but I'm running into a few problems with formatting. How can I set the cursor so that it normally is an arrow, but changes to a text cursor when hovering over text? (In essence, the behavior a cursor has within a web browser). I tried EditorPane.setCursor(new Cursor(Cursor.TEXT_CURSOR)) but that made it

How do I get a JEditorPane to highlight the full width of a line (not just the text)?

▼魔方 西西 提交于 2019-12-10 16:09:25
问题 I'm trying to get a JEditorPane to highlight the full width of a displayed line. All the examples I've tried only highlight the textual content. For example if I have content such as this: --------------------------------- |Here is some text | |some more text | --------------------------------- within a JEditorPane represented by the box above, then highlighting the first row highlights only the 'Here is some text' (represented between [ and ] below). --------------------------------- [Here

JEditorpane vs. JTextPane

倖福魔咒の 提交于 2019-12-10 12:38:43
问题 i have to create a project in java swing for my college. An editor of java files with proper text highlighting i.e different colors and fonts for java keywords , java comments and for normal text . Help me to select one of two styled text component JEditorpane and JTextPane provided by java so that i can full-fill the requirements. Please tell me suitable difference between these two that in which kind of situation i have to use one of these. 回答1: You can use either of them, but if it is a