EditTextField

// Create the text component
JTextComponent textComp = new JTextField("Initial Text");
Document doc = textComp.getDocument();

try {
    // Insert some text at the beginning
    int pos = 0;
    doc.insertString(pos, "some text", null);

    // Insert some text after the 5th character
    pos = 5;
    doc.insertString(pos, "some text", null);

    // Append some text
    doc.insertString(doc.getLength(), "some text", null);

    // Delete the first 5 characters
    pos = 0;
    int len = 5;
    doc.remove(pos, len);

    // Replace the first 3 characters with some text
    pos = 0;
    len = 3;
    doc.remove(pos, len);
    doc.insertString(pos, "new text", null);
} catch (BadLocationException e) {
}


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.