jtextpane

Toggling text wrap in a JTextpane

淺唱寂寞╮ 提交于 2019-11-29 12:17:09
How would I go about toggling text wrap on a JTextpane ? public JFrame mainjFrame = new JFrame("Text Editor"); public JTextPane mainJTextPane = new JTextPane(); public JScrollPane mainJScrollPane = new JScrollPane(mainJTextPane); mainjFrame.add(mainJScrollPane); See No Wrap Text Pane . Edit: Well, if you want to toggle the behaviour, then you would also need to toggle the getScrollableTracksViewportWidth() value. See Scrollable Panel . You should be able to toggle between FIT and STRETCH. package test; import java.awt.BorderLayout; import javax.swing.JButton; import javax.swing.JFrame; import

(Java Swing) How do I create a JTextPane with multiple icons on the same line?

天大地大妈咪最大 提交于 2019-11-29 07:59:43
As the question states, how do I successfully place multiple icons on the same line of text in a JTextPane ? Every time I try to change the value of actionText , the results are very unpredictable. As an example, this is the kind of thing I'm trying to achieve : If I pass just the icon-tokens to create icons (" ", for example), they just stack on top of each other (or maybe not, hard to tell). If I put " , " or " and ", then the first fighter-icon appears on the first line, while the comma and other fighter-icon appears on the second line. I am currently trying using a solution built upon the

JTextPane/JTextField strange behaviour with rare characters

核能气质少年 提交于 2019-11-29 07:39:56
I've discovered a strange bug in JTextPane/JTextField (or somewhere in the font rendering underneath them). I wonder if anyone else has encountered the same and might have a solution for this. I'm trying to display some "special" or rare characters in a JTextPane, and as soon as I change the font of the JTextField (which is completely unrelated to JTextPane!), the JTextPane "breaks up", and no longer displays these characters. This should do a better job explaining what I mean: public class Scrap { public static void main(String[] args) { JFrame frame = new JFrame(); frame

JTextPane text background color does not work

我们两清 提交于 2019-11-29 07:30:14
I am trying to make a small HTML-wysiwyg with a JTextPane but I can't get the BackgroundAction to work. I am using setCharacterAttributes on the StyledDocument of the JTextPane but it seems problematic. The view is ok but the Document is not. Here is a small demo code showing the problem. There are 2 JTextPane : I set the background color of my text in the first one I retrieve the text of the first JTextPane and set it on the second one --> They don't show the same thing although they have the same text. Is there a way to set the background color on the current selected text and have the

Search text file and display results in a JPanel

ぐ巨炮叔叔 提交于 2019-11-29 07:19:01
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 JTextField, JTextPane, whichever best applicable). I'd like the search results to show in columns like how

Adding tooltips to JTextPane

自古美人都是妖i 提交于 2019-11-29 04:03: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? 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 done by Swing itself. Tooltip is created by ToolTipManager. When you call setToolTipText() Jcomponent adds the

JTextPane highlighting issue

徘徊边缘 提交于 2019-11-29 02:45:11
The last days I have been trying to implement a highlighting feature in a small text editor. For some reason I get a strange result: The given example should highlight each "dolor" - the first occurences are correctly found and highlighted but the next ones aren't. Here is the code I wrote so far: import java.awt.Color; import java.awt.Dimension; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTextPane; import javax.swing.text.BadLocationException; import javax.swing.text.DefaultHighlighter;

Getting raw text from JTextPane

坚强是说给别人听的谎言 提交于 2019-11-29 02:21: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>foobar</b></font><br> blabla </body> </html> instead of getting only the raw content: blabla foobar blabla

Wrap long words in JTextPane (Java 7)

懵懂的女人 提交于 2019-11-29 01:24:56
In all versions of Java up to 6, the default behaviour of a JTextPane put inside a JScrollPane was: wrap lines at word boundaries if possible. If not, then wrap them anyway. In JDK 7, the default behaviour seems to be: wrap lines at word boundaries if possible. If not, just expand the width of the JTextPane (never wrap long words). It is easy to reproduce this, here is a SSCCE: public class WrappingTest extends JFrame { public static void main ( String[] args ) { new WrappingTest(); } public WrappingTest () { setSize(200,200); getContentPane().setLayout(new BorderLayout()); JTextPane jtp = new

Get a component from a JTextPane through javax.swing.text.Element?

好久不见. 提交于 2019-11-28 13:46:56
I am using a JTextPane to display characters and symbols, where the latter are represented by custom painted JComponents . For example, the text pane might show something like this: The text pane is user editable and it is allowed for the user to add more symbols via a button at any position and as a replacement for selected text. I do this via the JTextPane.insertComponent() method. At some point in the application I need to know what is currently being displayed in the text pane, and by that I mean not only the entered text, but also the exact components contained within. I went through