List of usage examples for javax.swing.text JTextComponent getDocument
public Document getDocument()
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextComponent textComp = new JTextArea(); Document doc = textComp.getDocument(); Position p = null;/*from w ww. j ava 2s .c o m*/ int location = 3; p = doc.createPosition(location); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextComponent textComp = new JTextField("Initial Text"); Document doc = textComp.getDocument(); // Append some text doc.insertString(doc.getLength(), "some text", null); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextComponent textComp = new JTextField("Initial Text"); Document doc = textComp.getDocument(); // Insert some text after the 5th character int pos = 5;/* w ww .j a v a2 s. com*/ doc.insertString(pos, "some text", null); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextComponent tc = new JTextArea("Initial Text"); int docLength = tc.getDocument().getLength(); String text = tc.getText();/*from ww w. j a va2s . c o m*/ // Get the last 3 characters int offset = docLength - 3; int len = 3; text = tc.getText(offset, len); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextComponent textComp = new JTextField("Initial Text"); Document doc = textComp.getDocument(); // Delete the first 5 characters int pos = 0;//from ww w. ja v a 2 s . com int len = 5; doc.remove(pos, len); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextComponent tc = new JTextArea("Initial Text"); int docLength = tc.getDocument().getLength(); // Get all text String text = tc.getText();/*from ww w .j av a 2s.c o m*/ // Get the first 3 characters int offset = 0; int len = 3; text = tc.getText(offset, len); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextComponent textComp = new JTextField("Initial Text"); Document doc = textComp.getDocument(); // Replace the first 3 characters with some text int pos = 0;/* w w w .j a v a2 s .c om*/ int len = 3; doc.remove(pos, len); doc.insertString(pos, "new text", null); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextComponent c = new JTextArea(); c.getCaretPosition();/*from w ww . j ava 2s. co m*/ if (c.getCaretPosition() < c.getDocument().getLength()) { char ch = c.getText(c.getCaretPosition(), 1).charAt(0); } // Set the caret color c.setCaretColor(Color.red); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextComponent c = new JTextArea(); c.getCaretPosition();/* www . j a va2s . co m*/ if (c.getCaretPosition() < c.getDocument().getLength()) { char ch = c.getText(c.getCaretPosition(), 1).charAt(0); } // Move the caret int newPosition = 0; c.moveCaretPosition(newPosition); }
From source file:Main.java
public static void main(String[] argv) { JTextComponent textComponent = new JTextField(); AbstractDocument doc = (AbstractDocument) textComponent.getDocument(); doc.setDocumentFilter(new FixedSizeFilter(10)); }