StyledDocument « Text Input « Java Swing Q&A





1. Java StyledDocument: How can I ensure that what the user types never appears already styled?    stackoverflow.com

The user types some text. When they press a button, what they have typed is split up and colour coded:

colors.setCharacterAttributes(characters, tokens[x].length(), formatBlue, true);
Using a set of rules.
When they make an edit ...

2. AttributeSet and StyledDocument's setCharacterAttributes with HTMLDocument    coderanch.com

Hey, Got an interesting problem here. I'm using setCharacterAttributes on an HTMLDocument to set up things like font size and family. This works as long as there is no current setting that was on the text when it was loaded. However, if the character range has a current setting from the document load, then it won't be modified by the new ...

4. Question on StyledDocument.    coderanch.com

Hi everyone, My application consists of a simple GUI with a textField, a button and a textpane.The requirement is tht user types a command and hits the button upon which the command and response from a remote element should be logged in the textPane.Also after each cmd + response, the screen should be cleared and new set of cmd + resp ...

5. IllegalStateException in a StyledDocument    coderanch.com

import javax.swing.*; import javax.swing.text.*; import javax.swing.event.*; import java.awt.*; class ErrorPane extends JFrame { public ErrorPane() { super("ErrorPane"); JTextPane textPane = new JTextPane(); textPane.setPreferredSize(new Dimension(100,50)); textPane.getStyledDocument().addDocumentListener(new MyDocumentListener()); getContentPane().setLayout(new FlowLayout()); getContentPane().add(textPane); } protected class MyDocumentListener implements DocumentListener { public void insertUpdate(DocumentEvent e) { SimpleAttributeSet attrs = new SimpleAttributeSet( ); StyleConstants.setForeground(attrs, Color.blue); try{ ((StyledDocument)e.getDocument()).insertString(0,"text inserted",attrs); }catch(BadLocationException ble){System.out.println(ble.toString());}; } public void removeUpdate(DocumentEvent e) { SimpleAttributeSet ...

6. StyledDocument and Paragraphs    coderanch.com