jtextpane

Word wrapping in JTextPane

风格不统一 提交于 2019-12-10 19:19:29
问题 I have a word wrapping issue when using JTextPane. I think it's my IDE (JCreator) but when i use the source everyone else is using I get several errors. Sorry for the line breaks... Could it be my IDE or can someone please let me know the right way of doing this. TIA -Roland The source I am using can be found at http://java-sl.com/tip_html_letter_wrap.html lol.. I forgot the space! Thanks all. It is going to proceed. I have been programming all night and am a little groggy. Best of luck

Make JTextPane adjust height to content

杀马特。学长 韩版系。学妹 提交于 2019-12-10 17:35:41
问题 I'm trying to get a JTextPane to adjust its height according to whatever content I feed it. All I can do is to set a fixed height in pixels using Dimension. How do I make the JTextPane collapse/expand so it will fit to contents? I might add that I use this in a GridBagLayout 'ed JPanel that has been added to a JScrollPane . 回答1: I don't know any direct way to do it, but this may give you some ideas: import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.text.*;

Changing the size of JTextPane

一个人想着一个人 提交于 2019-12-10 16:15:08
问题 I am new in Java, and I just found this piece of code in StackOverflow: ResizeTextArea. I want to use JTextPane instead of JTextArea . In JTextPane , there is no setRows() method to change the number of the lines. Any help would be appreciated. 回答1: The height of individual lines in a StyledDocument can vary, so the notion of limiting rows in a JTextPane is not useful. You can limit the preferred size of the scroll pane's viewport to some useful fraction of main panel's size, as shown here

Syntax-Highlighting in JTextPane using SwingWorker

雨燕双飞 提交于 2019-12-10 15:09:12
问题 I am trying to do text highlighting in JTextPane . I'm using SwingWorker to do highlighting in background. But i'm unable to get desired output. My Code is as Follow: Main Class: class MultiColor { private static void displayGUI() { final JTextPane ta = new JTextPane(); JFrame frame = new JFrame("EXAMPLE"); JButton jb = new JButton("Change"); JScrollPane jsp = new JScrollPane(ta); frame.add(jsp, BorderLayout.CENTER); frame.add(jb, BorderLayout.PAGE_END); frame.pack(); frame

Adding text to a JTextPane without having it editable by the user?

这一生的挚爱 提交于 2019-12-10 13:24:12
问题 So I've created my own text pane class (extending JTextPane) and I'm using the method below to add text to it. However, the pane needs to be editable for it to add the text, but this allows a user to edit what is in the pane as well. Can anyone tell me how to add text to the pane without letting the user manipulate what is there? public void appendColor(Color c, String s) { StyleContext sc = StyleContext.getDefaultStyleContext(); AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY,

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

蓝咒 提交于 2019-12-10 13:17:32
问题 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 and removeString methods inside the StyledDocument. After much testing, i have completed comments and keywords. Q1: As for my Strings coloring, I color my strings based on this regular expression: Pattern strings = Pattern.compile("\"[^\"]*\"");

JEditorpane vs. JTextPane

倖福魔咒の 提交于 2019-12-10 12:38:43
问题 i have to create a project in java swing for my college. An editor of java files with proper text highlighting i.e different colors and fonts for java keywords , java comments and for normal text . Help me to select one of two styled text component JEditorpane and JTextPane provided by java so that i can full-fill the requirements. Please tell me suitable difference between these two that in which kind of situation i have to use one of these. 回答1: You can use either of them, but if it is a

Limit JTextPane space usage

耗尽温柔 提交于 2019-12-10 11:29:32
问题 I'm using JTextPane to log some data from a network application and after the program runs for about more than 10 hours or so I get memory heap error. Text continues to get added to the JTextPane which keeps increasing memory usage. Is there anyway I can make the JTextPane act like a command prompt window? Should I get rid of the old text as new text comes in? This is the method I'm using to write to the JTextPane. volatile JTextPane textPane = new JTextPane(); public void println(String str,

Keeping the format on text retrieval

旧街凉风 提交于 2019-12-10 10:54:50
问题 I am making a network application that has a chat function. On the chat I have one JTextPane for displaying messages and one more for input. Then I have some buttons that allow to add style on the input text(bold,italic,font size,colour). The text is formatted correctly on input pane , although when moved to the display pane(once the correct JButton is pressed) it only has the format of last character. How can I move the text while keeping its original format?For example if I write "Hello

How to output using StyledDocument with HTML?

大憨熊 提交于 2019-12-10 10:38:40
问题 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); StyleConstants.setFontFamily(style, Font.SANS_SERIF); StyleConstants.setFontSize(style, 8); dox.insertString(dox.getLength(), "<b>Some Text</b>", null); The problem right now is if I edit the text with html code, it does not display the way I want. I want the text to be