I'm looking for a method that computes the line number of a given text position in a JTextPane with wrapping enabled.
Example:
This a very very very very very very very very very very very very very very very very very very very very very very long line.
This is another very very very very very very very very very very very very v...
In a JTextPane with a DefaultStyledDocument the document structure (hierarchy of Element objects) ends with a LeafElement that spans all the character of the enclosing paragraph. Is there a way to customize the document such that each leaf element will represent a single character?
(Background: I am trying to implementing a custom color...
I have a JFrame that contains a JTextPane. The purpose of this JTextPane is to highlight words as I type them, something along the lines of a programmer's text editor. To accomplish this, I extended JTextPane, I implemented the KeyListener interface, and I had it setup as a key listener to self. The method that does some important work i...
Hi, I've got a couple thousand lines of code somewhere and I've noticed that my JTextPane flickers when I update it too much.. I wrote a simplified version here:
import java.awt.*;
import javax.swing.*;
public class Test
{
static JFrame f;
static JTextPane a;
static final String NL = "\n";
public static void main(Strin...
How do I easily edit the style of the selected text in a JTextPane? There doesn't seem to be many resources on this. Even if you can direct me to a good resource on this, I'd greatly appreciate it.
Also, how do I get the current style of the selected text? I tried styledDoc.getLogicalStyle(textPane.getSelectionStart()); but it doesn't s...
Lets say that I have a JTextPane that is showing a HTML document.
I want that, on the press of a button, the font size of the document is increased.
Unfortunately this is not as easy as it seems... I found a way to change the font size of the whole document, but that means that all the text is set to the font size that I specify. What...
I'm trying to get a JTextPane to adjust its height according to whatever content I feed it. All I can do is to set a fixed height in pixels using Dimension.
How do I make the JTextPane collapse/expand so it will fit to contents?
I might add that I use this in a GridBagLayout'ed JPanel that has been added to a JScrollPane.
...
I need to take text from a source as plain text and display it in a JTextPane or JEditorPane. The source text is not HTML but will contain URLs between square brackets which need to be displayed and function as hyperlinks.
I've considered setting the pane's content type to text/html and surounding the url in html tags but that ends up i...
I have the following "tree" of objects:
JPanel
JScrollPane
JPanel
JPanel
JScrollPane
JTextPane
When using the mouse wheel to scroll over the outer JScrollPane I encounter one annoying problem. As soon as the mouse cursor touches the inner JScrollPane, it seems that the scroll...
I'm using a JTextPane to edit HTML. When I enter newlines in the GUI component and call getText() on the JTextPane, I get a string with newline characters. If I then create a new JTextPane and pass that same text in, the newlines are ignored.
Why doesn't JTextPane insert a <br> tag when a newline is entered? Is there a good workaroun...
I'm trying to create a simple WYSIWYG editor that will allow users to select text and bold/underline/italicise it. Currently the user can select text, right-click it and select bold from a popup menu, which ends up applying the bold style to the selected text like so:
this.getStyledDocument().setCharacterAttributes(this.getSelectionStar...
I currently use a JTextPane to allow users to add/edit text. It allows bold/italic/underline (and I plan to allow links in the future). It also allows users to drop buttons in, which are inserted as custom styles. The panel looks like:
I would like to be able to save/load content as HTML - the content will be incorporated in a Flash s...
A JTextPane lets you embed JComponents and images. When you select a section of the document the text is highlighted but the embedded items are not. You can have the embedded components notified by way of a CaretListener after the event, but I was wondering if there was a way to have them highlighted during mouse selections?
...
Is it possible to change the background color of a paragraph in Java Swing? I tried to set it using the setParagraphAttributes method (code below) but doesn't seem to work.
StyledDocument doc = textPanel.getStyledDocument();
Style style = textPanel.addStyle("Hightlight background", null);
StyleConstants.setBackground(style, ...
I'm trying to create a WYSIWYG editor using JTextPane.
I'm using DefaultEditorKit.CopyAction to copy text in the editor. But this method does not preserve the style of the text. Can someone tell me how to copy the text in JTextPane and preserve the style, please ?
...
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, bu...
Hi,
I have a JTextPane integration that should perform predefined steps on keypress events. If I type manually it seems to work fine. But I have to emulate keypress events on this integration for test purposes. The test enviroment is such that the given JTextPane is not added to any other controls. I tried to use Robot class, after set ...
I have a JTextPane (or JEditorPane, I can use either no problem). How can I change the font of a selected area to a specific font?
textpane.getSelectedText().setFont() won't work. (Even with font-family)
...
I am creating a SQL editor. I am using JTextPane for the editor. I want to implement AutoCompletion for table name etc. like Eclipse.
...
I have an HTML document being displayed by a JTextPane that works very nicely. I have some buttons that I interact with using ActionListeners for a ButtonModel, and I hook into state links (#foo) to handle simple internal app links.
My problem is that I have a INPUT element that I need to change the "value" of so the text changes in the...