Example usage for javax.swing.text Document createPosition

List of usage examples for javax.swing.text Document createPosition

Introduction

In this page you can find the example usage for javax.swing.text Document createPosition.

Prototype

public Position createPosition(int offs) throws BadLocationException;

Source Link

Document

This method allows an application to mark a place in a sequence of character content.

Usage

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  ww  w . jav  a2  s.c o  m

    int location = 3;
    p = doc.createPosition(location);

}

From source file:TextCutPaste.java

/**
 * Bundle up the data for export.//w  ww  .  j a  va 2 s.  c om
 */
protected Transferable createTransferable(JComponent c) {
    JTextField source = (JTextField) c;
    int start = source.getSelectionStart();
    int end = source.getSelectionEnd();
    Document doc = source.getDocument();
    if (start == end) {
        return null;
    }
    try {
        p0 = doc.createPosition(start);
        p1 = doc.createPosition(end);
    } catch (BadLocationException e) {
        System.out.println("Can't create position - unable to remove text from source.");
    }
    String data = source.getSelectedText();
    return new StringSelection(data);
}

From source file:DragColorTextFieldDemo.java

protected Transferable createTransferable(JComponent c) {
    source = (JTextComponent) c;/*from   w  w  w .j a  v a 2s .c  o m*/
    int start = source.getSelectionStart();
    int end = source.getSelectionEnd();
    Document doc = source.getDocument();
    if (start == end) {
        return null;
    }
    try {
        p0 = doc.createPosition(start);
        p1 = doc.createPosition(end);
    } catch (BadLocationException e) {
        System.out.println("Can't create position - unable to remove text from source.");
    }
    shouldRemove = true;
    String data = source.getSelectedText();
    return new StringSelection(data);
}

From source file:DragFileDemo.java

protected Transferable createTransferable(JComponent c) {
    source = (JTextArea) c;/*from w w w. j  av a2s  .  c  o  m*/
    int start = source.getSelectionStart();
    int end = source.getSelectionEnd();
    Document doc = source.getDocument();
    if (start == end) {
        return null;
    }
    try {
        p0 = doc.createPosition(start);
        p1 = doc.createPosition(end);
    } catch (BadLocationException e) {
        System.out.println("Can't create position - unable to remove text from source.");
    }
    shouldRemove = true;
    String data = source.getSelectedText();
    return new StringSelection(data);
}