Modifying Text in a JTextComponent: Insert some text at the beginning
import javax.swing.JTextField;
import javax.swing.text.Document;
import javax.swing.text.JTextComponent;
public class Main {
public static void main(String[] argv) throws Exception {
JTextComponent textComp = new JTextField("Initial Text");
Document doc = textComp.getDocument();
// Insert some text at the beginning
int pos = 0;
doc.insertString(pos, "some text", null);
}
}
Related examples in the same category