styleddocument

Java Setting Indent Size on JTextPane

做~自己de王妃 提交于 2019-12-01 22:46:55
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 JEditorPane? JTextPane is not a plain document. Java JTextpane Tab Size Eclipse raised some errors: Type mismatch: cannot convert from javax.swing.text.AttributeSet to javax.print.attribute.AttributeSet and The method setParagraphAttributes(javax.swing.text.AttributeSet, boolean) in the type JTextPane is not applicable for the arguments (javax.print.attribute

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

JTextPane text background color does not work

隐身守侯 提交于 2019-11-28 01:03:03
问题 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

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

左心房为你撑大大i 提交于 2019-11-27 15:15:22
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 words - if there is a string of text without spaces that is wider than the window, it won't wrap/break and a horizontal scrollbar will appear. As the text width increases, the width of the ParagraphView (via getWidth()) increases to hold the text. This article by Lapitsky says that LabelView.getBreakWeight() returns View.ExcellentBreakWeight for

JTextPane appending a new string

狂风中的少年 提交于 2019-11-26 20:08:15
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("<b>Termination time : </b>" + CriterionFunction.estimateIndividual_top(individual) + " </br>"); jep.setText(jep.getText() + "Processes' distribution: </br>"); And as a result I got "Termination time : 1000" without "Processes' distribution:" Why did this happen??? camickr I doubt that is the recommended approach for appending text. This means every time you change some text you need to reparse the entire document. The

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

喜欢而已 提交于 2019-11-26 16:54:34
问题 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 JTextPane(doc); textpane.setText("Test"); javax.swing.text.Style style = textpane.addStyle("Red", null); StyleConstants.setForeground(style, Color.RED); doc.setCharacterAttributes(0, 1, textpane.getStyle("Red"), true); This is useful if you have only a few

JTextPane appending a new string

点点圈 提交于 2019-11-26 07:32:22
问题 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(\"<b>Termination time : </b>\" + CriterionFunction.estimateIndividual_top(individual) + \" </br>\"); jep.setText(jep.getText() + \"Processes\' distribution: </br>\"); And as a result I got \"Termination time : 1000\" without \"Processes\' distribution:\" Why did this happen??? 回答1: I doubt that is the recommended