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
0
votes
1 answer

Can you use or combine two different AttributeSets in the same piece of text in jTextPane?

I have a JTextPane that displays some text. It is generated dynamically. The program receives, from a socket, the style of the text and the text itself. As an example, I want some parts of the text to be bold, some others to be centered, and some…
0
votes
0 answers

JTextPane remove background set via setCharacterAttributes

I working on my own editor, for which I want to add a background colour to text a user might search for. Finding the text and setting a background colour is not a problem, the problem is how can I remove the background colour when the focus…
munyul
  • 1,188
  • 1
  • 14
  • 24
0
votes
1 answer

Java StyledDocument insertString() in a loop

I am currently writing a really simple program using JSwing. There is a JTextArea ("textArea") inside a JScrollPane ("textPane"). I managed to edit texts and stuff in this TextArea with a StyledDocument named doc. However, when I want to insert a…
justadzr
  • 103
  • 3
0
votes
1 answer

How to save a StyledDocument from textPane into a .doc file?

I don't know if this is even possible, but what I would like to do is to save a Styled Document (user can change text: bold, underline, italic and 3 sizes of font) in a .doc file - so he could open it later on his own with any other text editor that…
Ves
  • 15
  • 5
0
votes
1 answer

Swing DefaultStyledDocument traversal

I'm trying to pull out the four paragraphs that I've added to a DefaultStyledDocument. But it's not behaving as I would expect. What am I doing wrong? I've added the full code here - as that was what was requested. import javax.swing.*; import…
wax_lyrical
  • 844
  • 9
  • 21
0
votes
4 answers

Java Swing StyledDocument get Element tree / SelectedText Styling like bold, italic

Hey i have some questions/problems. I have to create a little program for text editing. The (selected) text should be style. Bold, Italic, Underline, Right- left- center alignment. It works great. I used the specific StyleEditorKit Actions. My…
Torben G
  • 641
  • 7
  • 21
0
votes
2 answers

Making JLable in JTextPane Undeletable

I currently have a JLabel embedded in a JTextPane using this: import javax.swing.*; import javax.swing.text.*; public class MainFrame { JFrame mainFrame = new JFrame("Main Frame"); JTextPane textPane = new JTextPane(); public…
Jonah
  • 983
  • 13
  • 25
0
votes
1 answer

Questions about relationship between StyledDocument and JTextPane, and the proper usage of interface

I am new to java and working on java swing GUI. Recently I read a post: Centering Text in a JTextArea or JTextPane - Horizontal Text Alignment The solution inside worked perfectly but I have some conceptual questions to ask. I read the introduction…
matthewhang
  • 165
  • 1
  • 2
  • 11
0
votes
1 answer

How to persistently store styled text from a Document in a database?

So I'm currently working on a program that allows users to created "posts" with styled text. Right now I'm using Java's DefaultStyledDocument, but I'm open to other options (preferably they implement StyledDocument, though). I originally posted…
DonyorM
  • 1,670
  • 1
  • 18
  • 31
0
votes
1 answer

How to get the content with all attributes of a JTextPane?

I have a JTextPane and on a ActionEvent, I want to save the content of the JTextPane (with the colors, text and other attributes) in another class (as a variable). Later on I want to exchange the content of the JTextPane with the one of the…
user3549340
  • 111
  • 2
  • 2
  • 7
0
votes
1 answer

Splitting StyledDocument

I am currently writing a program that accepts styled text in a JTextPane and also displays the same styled text in a non-editable JTextPane. The problem is that I actually want to parse the documents between inputting and displaying. Basically I…
DonyorM
  • 1,670
  • 1
  • 18
  • 31
0
votes
0 answers

Fix style of DefaultStyledDocument

I am wondering if it is possible to fix the style of StyledDocument in java. According to my observation, the style will change depending on style of previous position. So I can key in the content with my defined style without being affected by the…
johnklee
  • 1,670
  • 2
  • 13
  • 20
0
votes
1 answer

Is it possible to set length of paragraph in JTextPane StyledDocument?

I am using JTextPane with StyledDocument, is it possible to set length of its paragraph? My goal is when the length of text which is inserted in the JTextPane is longer than 400px, exceed go to new line. Edit: I use method below to set style for…
user90
  • 73
  • 3
  • 12
0
votes
1 answer

Java styleddocument change attribute for next input

I have JTextPane and a checkbox representing lets say bold font. So if checkbox is checked, I want whatever I type in JTextPane to be bold. I do not want to change whole font for JTextPane , I just want to set next char to be bold. I made this, and…
JollyRoger
  • 19
  • 1
  • 4
0
votes
2 answers

How can my JTextPane display multiple fonts?

I'm trying to design a part of a bigger GUI that will format some text to look good. It should be able to play with text in a lot of funny ways. Adding borders, underlining, i.e anything I could want to do with text for decorative purposes. Is…
user2651804
  • 1,134
  • 4
  • 16
  • 41