jtextpane

Setting the tab policy in Swing's JTextPane

社会主义新天地 提交于 2019-12-02 09:08:02
问题 I want my JTextPane to insert spaces whenever I press Tab. Currently it inserts the tab character (ASCII 9). Is there anyway to customize the tab policy of JTextPane (other than catching "tab-key" events and inserting the spaces myself seems an)? 回答1: You can set a javax.swing.text.Document on your JTextPane. The following example will give you an idea of what I mean :) import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JTextPane; import javax.swing.text.AttributeSet;

Remove JTextPane's white background without setOpaque() over a translucent JFrame

Deadly 提交于 2019-12-02 08:28:53
问题 I have a Java code where I implemented a translucent JPanel with an image drawn on it with Graphics 2D. This image is a PNG that includes a white rectangle, 80% opaque, all over the JFrame. Now I need to add a JTextPane to display datas (I set it to use a custom font from the app package BTW), but I can't manage to make it translucent : its white background is opaque (even with the textPane.setOpaque(false); setting) and makes the transparency of my JFrame a bit useless... Wich is not cool.

How does setCharacterAttributes take account of '\n' and '\t'?

半城伤御伤魂 提交于 2019-12-02 07:55:46
问题 I am working in school project for creating a simple IDE. In it I am processing the entire program as a single string like... import java.io.*\npublic class A{\n...........\0 To trace all /*comments*/ "strings" 'c'haracters /**Documentation*/ I am maintaining an ArrayList<Pair> to mark all positions. Say, if (23,34) is an entry in ArrayList<Pair> comments , this means the characters between 23 and 34 are in a comment. And I acheived that using setCharacterAttributes defined in StyledDocument

HTML wrapped String creates a unwanted new line in JtextPane output

假装没事ソ 提交于 2019-12-02 07:39:08
问题 When I concentrate a String with a HTML formatted string, and output the String to a JTextPane with a HTMLEditor kit, every appended String wrapped in the HTML tags appears to cause a new line: // Set the HTML Editor kit for JTExtPAne jtextPane.setEditorKit(new HTMLEditorKit()); String saveCurrentSentenceState = "Some String"; String newWord = "new word"; // wrap this in HTML tags // Create a HTML String String appendHTML = "<html><font color=\"red\">"+newWord+"<</font>"; // Concatenate with

Setting the tab policy in Swing's JTextPane

↘锁芯ラ 提交于 2019-12-02 07:15:56
I want my JTextPane to insert spaces whenever I press Tab. Currently it inserts the tab character (ASCII 9). Is there anyway to customize the tab policy of JTextPane (other than catching "tab-key" events and inserting the spaces myself seems an)? You can set a javax.swing.text.Document on your JTextPane. The following example will give you an idea of what I mean :) import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JTextPane; import javax.swing.text.AttributeSet; import javax.swing.text.BadLocationException; import javax.swing.text.DefaultStyledDocument; public class

Java Setting Indent Size on JTextPane

徘徊边缘 提交于 2019-12-02 06:20:43
问题 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

Java Default Highlighter

人盡茶涼 提交于 2019-12-02 05:33:06
问题 Im using the DefaultHightlighter.DefaultHightlighterPainter to highlight text within a java text pane. I want to remove all highlights (there could be more than one string highlighted) and want it to return the locations of the strings where the highlight has been removed, so obviously I cant use pseudoCodeTextPane.getHighlighter().removeHighlight(highlight); Can anyone help? Thanks 回答1: How about something like Highlighter.Highlight[] highlights = pseudoCodeTextPane.getHighlighter()

Java JTextPane + JScrollPane: de/activate automatic scrolling

北慕城南 提交于 2019-12-02 04:41:10
问题 I'm currently writing a simple chat in Java and currently I'm stuck on this problem: I want my output JTextPane to behave like you would expect it to from a good chat, ie by default the text scrolls automatically when new text arrives (using outputfield.setCaretPosition(outputdocument.getLength())), but when the user scrolls up this should be disabled and of course re-enabled when the user scrolls to the bottom again. I tried toying around with the ScrollBars and all, but I can't seem to find

JTextPane append HTML string

泄露秘密 提交于 2019-12-02 03:49:56
I can parse the content of a JTextPane witout any problems in HTML: textPane = new JTextPane(); textPane.setContentType("text/html"); textPane.setText(<b>Hello!</b>); // ... setVisible(true); this results in Hello! But whenever I try to append a String to textPane, using styledDoc = (StyledDocument) textPane.getStyledDocument(); styledDoc.insertString(styledDoc .getLength(), <b>Goodbye!</b>, null ); (as seen in this question ), my output is Hello! <b>Goodbye!</b> (without whitespaces) - so the html formatting is skipped. How can I append a String to my JTextPane Object and keep the HTML

Can't remove extra line spacing in JTextPane for html content

做~自己de王妃 提交于 2019-12-02 03:22:20
I can't squeeze together the lines in a Java JTextPane if I set the content-type to text/html . I would like them as close together as they are when the content-type is text/plain , the default. The line-height , top-margin , ... CSS properties don't seem to help :(. This is the output of my sample program, that shows that the lines do take more space when a HTML editor handles the rendering: alt text http://lh6.ggpht.com/_Wx4sMDdKKdU/S8cYWIPKhzI/AAAAAAAAAig/4QzFwygmEBs/simpleTextPane.PNG The code that generates the frame is: import java.awt.BorderLayout; import java.awt.Dimension; import