List of usage examples for javax.swing JTextField getSelectionStart
@Transient public int getSelectionStart()
From source file:TextCutPaste.java
/** * Bundle up the data for export.// ww w . j a va2 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); }