jtextpane

Search text file and display results in a JPanel

微笑、不失礼 提交于 2019-11-28 00:54:27
问题 Does anyone have any ideas on how I can search a text file and list the results in a JComponent, like a JPanel. I've been trying to make this work out for two days now, but no success will really appreciate a reply. Thanks a lot in advance. I've been trying to write a class that handles search queries to a text file. My main goal is to get the lines in a text file that contain the search keywords entered in a JTextField and print them out in an appropriate JComponent(something like a

Adding tooltips to JTextPane

感情迁移 提交于 2019-11-27 18:11:08
问题 I want to add some tooltips to only a certain text inside a JTextPane. As an example, if there is a reference link text inside the JTextPane I want to add a tooltip to that text to show the link. Is there any way I can achieve this functionality? 回答1: Good question. First Swing supports HTML, so to show tooltip with link you just have to say: comp.setToolTipText("<html><a href='http://www.google.com'>google</a></html>"); The problem is making this tooltip clickable. Unfortunately it is not

Getting raw text from JTextPane

こ雲淡風輕ζ 提交于 2019-11-27 16:55:51
问题 In my application, I use a JTextPane to display some log information. As I want to hightlight some specific lines in this text (for example the error messages), I set the contentType as " text/html ". This way, I can format my text. Now, I create a JButton that copies the content of this JTextPane into the clipboard. That part is easy, but my problem is that when I call myTextPane.getText() , I get the HTML code, such as : <html> <head> </head> <body> blabla<br> <font color="#FFCC66"><b

JEditorPane set foreground color for different words

ε祈祈猫儿з 提交于 2019-11-27 16:29:49
I am currently working on a text editor, and I have this code which make the background of the specific word different from the others, but I want the foreground to edit color and not the background. Here's the code I have: import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JEditorPane; import javax.swing.JFrame; import javax.swing.JTextPane; import javax.swing.text.AbstractDocument; import javax.swing.text.BadLocationException; import javax.swing.text.DefaultHighlighter;

setting JTextPane to content type HTML and using string builders

陌路散爱 提交于 2019-11-27 15:18:49
I'm using string builders to append text to my JTextPane, I've set content type as pane.setContentType("text/html"); but the no text actually appears on my JTextPane. This is an example of my append: buildSomething.append("<b style=\"color:pink\">"+Birthday+"</span>"); Is there something I'm doing severely wrong? And how do I go about fixit it? Every time JTextPane.setText(...) is called a new content type is determined. Start the text with "<html>" and you've got HTML. A new document is created, in your case HTMLDocument. @mKorbel: the following creates every time HTML for the JTextPane.

How is word-wrapping implemented in JTextPane, and how do I make it wrap a string without spaces?

左心房为你撑大大i 提交于 2019-11-27 15:15:22
How exactly is word-wrapping implemented in JTextPane? I'm trying to understand exactly how it works so that I can modify the behavior. Right now, if I have a standard JTextPane inside a JScrollPane, it will break text at spaces, but not inside long words - if there is a string of text without spaces that is wider than the window, it won't wrap/break and a horizontal scrollbar will appear. As the text width increases, the width of the ParagraphView (via getWidth()) increases to hold the text. This article by Lapitsky says that LabelView.getBreakWeight() returns View.ExcellentBreakWeight for

JEditorPane with Javascript and CSS support

空扰寡人 提交于 2019-11-27 14:47:48
I am working on Swing using JEditorPane but it's not supporting the Javascript or some advanced tag like <object> etc. and not supporting the color, font style size etc. Is there any solution so that editor pane can display the HTML file as it is being displayed in normal HTML browser? current Java6/7 supporting only (upto) Html 3.2 with reduced support for css , for Html5 and quite full css support to use JavaFx Components , there are custom Java libraries with (full???) support of Html4/5, css and js but I'd be suggest to use JavaFX instead David Kroukamp +1 to mKorbel. Use JavaFX WebView

JTextPane highlight text

老子叫甜甜 提交于 2019-11-27 04:38:11
Can I highlight some text into a JTextPane starting from a value and ending from another value like the following but with the yellow color? "" JTextPane highlight text "" Thanks. As often there are several possibilities, depending on what you really mean by "highlight":-) Highlight by changing any style attributes of arbitrary text parts on the document level, something like SimpleAttributeSet sas = new SimpleAttributeSet(); StyleConstants.setForeground(sas, Color.YELLOW); doc.setCharacterAttributes(start, length, sas, false); Highlight via a Highlighter on the textPane level:

How to add text different color on JTextPane

ぃ、小莉子 提交于 2019-11-27 04:25:50
Can anybody help me with simple log, I have to add at first line on JTextPane log messages with chosen color ( green ok, red failure ). How to achieve this ? Snukus This will print out "BLAH BLEG" in two different colors. public class Main { public static void main(String[] args) { JTextPane textPane = new JTextPane(); StyledDocument doc = textPane.getStyledDocument(); Style style = textPane.addStyle("I'm a Style", null); StyleConstants.setForeground(style, Color.red); try { doc.insertString(doc.getLength(), "BLAH ",style); } catch (BadLocationException e){} StyleConstants.setForeground(style,

How to access jtextPane in a different form?

你说的曾经没有我的故事 提交于 2019-11-26 23:40:54
问题 I am developing an application where, when I select a value(file) from list it should be opened in jTextPane of a different form. I am using two panels one is mainpanel where my list is shown and one is ExcelSheet, when i click on a list value then mainpanel is closed and new form ExcelSheet is displayed but not the content of doc file in jTextPane. XWPFWordExtractor extractor=null; File file=null; String str=(String) list.getSelectedValue(); mainPanel.setVisible(false); new ExcelSheet()