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

jtextpane append
jtextarea format text
jtextpane center text
jtextpane vs jtextarea
jtextpane wrap text
jtextarea not editable
jtextarea scrollable

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, StyleConstants.Foreground, c);

    int len = getDocument().getLength(); 


    setCharacterAttributes(aset, false);



Update the Document directly:

StyledDocument doc = textPane.getStyledDocument();
doc.insertString("text", doc.getLength(), attributes);

Text « JTextPane « Java Swing Q&A, So I've created my own text pane class (extending JTextPane) and I'm using th Examples That Use Editor Panes and Text Panes; Using an Editor Pane to Display Text From a URL. One task that you can accomplish without knowing anything about the Swing text system is displaying text from a URL. Here is the code from that creates an uneditable editor pane that displays text formatted with HTML tags.

JTextPane pane = new JTextPane();
pane.setEditable(false);  // prevents the user from editting it.
// programmatically put this text in the TextPane
pane.setText("Hello you can't edit this!");

How to Use Editor Panes and Text Panes (The Java™ Tutorials , Adding text to a JTextPane without having it editable by the user? stackoverflow.​com. So I've created my own text pane class (extending JTextPane) and I'm  Setting JTextPane Font and Color. Swing’s javax.swing.JTextPane class represents a significant improvement over AWT’s TextArea.It allows complex combinations of character and paragraph attributes, embedded images and components, and other features that let you build styled text editors.

Ok Take 2:

JTextPane pane = new JTextPane();
DefaultStyledDocument document = (DefaultStyledDocument)pane.getDocument();
document.insertString( "Hello you can't edit this!", document.getEndPosition().getOffset(), null );

How do I create an uneditable JTextArea?, One task that you can accomplish without knowing anything JEditorPane editorPane = new //Put the editor pane in a scroll pane. so the user cannot edit the text. I've go a JTextPane placed on a JScrollPane, when I add a lot of text on it, the vertical scrollbar is going to the bottom, I want that TextPane view the Skip navigation Oracle Community Directory

JTextPane myTextArea = new JTextPane();

Create read-only (non-editable) JTextField, To make the JTextArea not editable call the setEditable() method and pass a new JScrollPane(textArea); this.add(scrollPane, BorderLayout. StyledDocument is a sub-interface of "+ "Document that contains methods for manipulating attributes that "+ "control the way in which the text in the document is displayed. "+ "The Swing text package contains a concrete implementation of "+ "StyledDocument called DefaultStyledDocument that is used as the "+ "default model for JTextPane and is

Java by Dissection, In order to create a non editable JTextField , all you have to do is: Use add to add the field to the frame. this textfield should be editable. It is therefore advisable to employ JTextArea, which employs text warping feature if there is no need to edit content by underlining it, making it bold or coloring it. This is because using JTextPane and not employing any of the styling feature results in a significant slowing down of the user interface.

Text Components - Learning Java, 4th Edition [Book], Whether a JTextField is editable by the user can be controlled with the method Using a JTextArea, adding simple text editing capability to any application is trivial. C.7 THE CLASS JPanel A JPanel has no appearance of 438 Summary of  Java Swing How to - Java JTextPane Example « Previous; Next » Java Add Border with equal sizes on all 4 sides of JTextpane; Java Color only a portion of JTextpane; Java Create formatted text to show in JTextPane; Java Create JEditorPane vertical alignment; Java Format JTextPane; Java Get DefaultCaret from JTextPane; Java Get text from JTextPane

How to Use Text Components, When you add or remove text from a JTextField or a JTextArea , the When the user hits Return in the JTextField , we receive an ActionEvent and add the line to the By default, JTextField and JTextArea are editable; you can type and edit in directly to methods in the cryptographic classes without ever creating a String . How to Use Text Areas The JTextArea class provides a component that displays multiple lines of text and optionally allows the user to edit the text. If you need to obtain only one line of input from the user, you should use a text field .