Example usage for javax.swing JTextField getSelectionEnd

List of usage examples for javax.swing JTextField getSelectionEnd

Introduction

In this page you can find the example usage for javax.swing JTextField getSelectionEnd.

Prototype

@Transient
public int getSelectionEnd() 

Source Link

Document

Returns the selected text's end position.

Usage

From source file:TextCutPaste.java

/**
 * Bundle up the data for export.//  ww  w  . ja  v a2  s  .c  o m
 */
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);
}