List of usage examples for javax.swing JTextField replaceSelection
public void replaceSelection(String content)
From source file:dnd.TextTransferHandler.java
/** * Perform the actual import. This method supports both drag and * drop and cut/copy/paste./* ww w .j a v a 2s. com*/ */ public boolean importData(TransferHandler.TransferSupport support) { //If we can't handle the import, bail now. if (!canImport(support)) { return false; } //Fetch the data -- bail if this fails String data; try { data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor); } catch (UnsupportedFlavorException e) { return false; } catch (java.io.IOException e) { return false; } JTextField tc = (JTextField) support.getComponent(); tc.replaceSelection(data); return true; }
From source file:TextCutPaste.java
/** * Perform the actual import. This method supports both drag and drop and * cut/copy/paste./*from w w w. j a va2s . c om*/ */ public boolean importData(TransferHandler.TransferSupport support) { // If we can't handle the import, bail now. if (!canImport(support)) { return false; } // Fetch the data -- bail if this fails String data; try { data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor); } catch (UnsupportedFlavorException e) { return false; } catch (java.io.IOException e) { return false; } JTextField tc = (JTextField) support.getComponent(); tc.replaceSelection(data); return true; }