Questions tagged [styleddocument]

`StyledDocument` is a Java interface that extends `Document`. It helps Swing Components like `JTextPane` to render HTML and other markup-language-content.

StyledDocument is a Java interface, extending Document, to help Swing Components like JTextPane that supports the javax.swing.text API to render HTML and other markup-language content. From the JavaDoc it just says:

Interface for a generic styled document.

You normally don't handle with this interface, Methods like JEditorPane.setContentPane() automatically installs the required StyledDocument on your Component.

58 questions
35
votes
3 answers

JTextPane appending a new string

In an every article the answer to a question "How to append a string to a JEditorPane?" is something like jep.setText(jep.getText + "new string"); I have tried this: jep.setText("Termination time : " + …
Dmitry
  • 2,878
  • 5
  • 41
  • 63
9
votes
3 answers

How can I set each character to a different color/background color in a JTextPane?

I've been searching for this for a while and so far all I've been able to come up with is how to create a style and apply it to a character like so: StyledDocument doc = (StyledDocument) new DefaultStyledDocument(); JTextPane textpane = new…
JaredL
  • 1,213
  • 2
  • 10
  • 24
6
votes
1 answer

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

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…
A Coder
  • 455
  • 1
  • 6
  • 16
6
votes
5 answers

Which is the right regular expression to use for Numbers and Strings?

I am trying to create simple IDE and coloring my JTextPane based on Strings (" ") Comments (// and /* */) Keywords (public, int ...) Numbers (integers like 69 and floats like 1.5) The way i color my source code is by overwritting the insertString…
user3188291
  • 527
  • 1
  • 6
  • 21
6
votes
1 answer

JTextPane text background color does not work

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…
Guillaume Polet
  • 45,783
  • 4
  • 79
  • 115
4
votes
2 answers

How to clear all styling from StyledDocument?

StyledDocument contains various methods to set styles. Like setCharacterAttributes. But I can't see any methods to remove styles. Is there any?
Dims
  • 37,353
  • 77
  • 251
  • 478
4
votes
3 answers

Change specific String attributes in StyledDocument

I am trying to create a text editor. I am using a JTextPane with a StyledDocument. What I am trying to implement is a way to change the attributes of selected text. This works in the following way : the user inputs the desired text. Afterwards, he…
3
votes
1 answer

Highlighter vs. StyledDocument of Java Swing for changing the color of text in a JTextPane

I've been using setCharacterAttributes of StyledDocument to change the colors of specific words or sections in a JTextPane. But then I noticed some answers here where they use a Highlighter (typically DefaultHighlighter) to do the same thing. What…
Gigatron
  • 1,905
  • 5
  • 20
  • 27
3
votes
1 answer

How to output using StyledDocument with HTML?

I have a JTextPane, and I would like to output text on it using StyledDocument. Here is my StyledDocument object StyledDocument dox = (StyledDocument) textArea.getDocument(); Style style = dox.addStyle("StyleName", null); …
livelaughlove
  • 366
  • 1
  • 8
  • 21
3
votes
2 answers

Font of a StyledDocument associated with a JTextPane

What font does the StyledDocument associated with a JTextPane use? By default, does it use the same font as the JTextPane? In particular, I'm wondering about the font size.
Paul Reiners
  • 8,896
  • 30
  • 107
  • 178
3
votes
2 answers

Java Setting Indent Size on JTextPane

I want to set the size of a tab character, \t, in a JTextPane to be 4 spaces wide. After Googling quite a bit I found some things that I will include here for what I have tried and maybe why they failed. How do you set the tab size in a…
Moon Cheesez
  • 2,319
  • 2
  • 19
  • 34
3
votes
1 answer

Issue with JTextPane and regex

I have a JTextPane which contains a string of XML characters, and I wish to change the colour of XML opening tags; to do this I use a regex to find the opening tags, then set the character attribute of the relevant text indexes to the chosen color.…
Hungry
  • 1,535
  • 1
  • 13
  • 24
3
votes
1 answer

Multi-color text selection in JTextPane (Swing)

I have a JTextPane, with styledDocuent. I've inserted programmatically the text: "Hello World". Word "Hello" is red, and word "World" is green. Is there any way I can select the two words, and the selection rectangle becomes half red half green(or…
user3499927
2
votes
1 answer

Set style and text of a jTextPane using a StyledDocument

I'm creating a basic Swing applcation. I have jTextPane and a button. If the user selects text in the jTextPane and presses the button, it bolds the selected text. This is done by modifying the StyleDocument. I want to be able to save the styled…
Corey Farwell
  • 1,806
  • 3
  • 14
  • 17
2
votes
1 answer

JTextPane and undo manager style change

My situation: I have a JTextPane with its own syntax highlighting. I have it set so that when the user stops typing, it updates the style in the text using the setCharacterAttributes() method. My Issue: When these updates to the style are not…
1
2 3 4