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.

65 questions
1
vote
0 answers

Indent part of JTextPane

Is there a way to indent text in a jtextpane using insertString? My question is similar to JTextPane indentation except that I would very much prefer to use insertString
kokocrunch
  • 41
  • 4
1
vote
1 answer

How to append a string in java swing JTextPane?

I am creating a chat application. In this chat application, I have to use Java Swing's JTextPane to give style to some specific strings like the user's display name and the message's time. That's why I chose JTextPane over JTextArea. In JTextPane, I…
boopathy
  • 427
  • 2
  • 9
  • 20
0
votes
0 answers

Update StyledDocument according to changed styles

I have a JTextPane, I have created some styles: Style assistant = addStyle("assistant", null); StyleConstants.setForeground(assistant, Color.decode("#01AF07")); Style user = addStyle("user", null); StyleConstants.setForeground(user,…
0
votes
1 answer

Why custom styled document can't work with custom filter document?

I am new to the java-swing library and currently I'm working on a text editor for a programming language. I have add the highlight key words future and it work fine. I also need to add other futures such as auto indent, auto pair,... To do this I…
Abdo21
  • 498
  • 4
  • 14
0
votes
0 answers

Java swing : StyledDocument padding and radius for paragraphs

I'm using StyledDocument and SimpleAttributeSet for my project but I'm having an UI issue. Here is what I have with my code right now : And here is what I would like to have : The first thing I'm trying to have is the padding, because the…
Madar
  • 196
  • 2
  • 15
0
votes
0 answers

Why does the formatting differ from console output and JTextPane?

I want to print out what essentially looks like a table to a JTextPane, something like this: What my output looks like currently is this: As you can see the columns do not line up really at all. In the console however it is perfect, and looks like…
carlb710
  • 29
  • 6
0
votes
0 answers

How to set the style of inputted text to that which immediately follows the cursor position in a JTextPane

I'm working on a database program where the GUI has multiple input areas, some of which are JTextPanes where the user can set Bold, Underline, and Italic styles on their text. When the user places their cursor immediately adjacent to an area that is…
0
votes
1 answer

Remove JTextPane Lines and Keep Styling

I'm using JTextPane and StyledDocument for styling message and I want to clear the messages or clear only the oldest message. I can easily clear all by using: textPane.setText(""); But if I want to clear all, except some lines, then not sure if/how…
Liron C
  • 171
  • 1
  • 12
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…
Eric
  • 1,321
  • 2
  • 15
  • 30
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

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
  • 922
  • 1
  • 10
  • 22
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
  • 750
  • 2
  • 11
  • 33
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
  • 1,013
  • 15
  • 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…
neurothew
  • 185
  • 1
  • 2
  • 11