Example usage for javax.swing.text JTextComponent cut

List of usage examples for javax.swing.text JTextComponent cut

Introduction

In this page you can find the example usage for javax.swing.text JTextComponent cut.

Prototype

public void cut() 

Source Link

Document

Transfers the currently selected range in the associated text model to the system clipboard, removing the contents from the model.

Usage

From source file:Main.java

static void dndCut(final Component component) {
    final JTextComponent textComponent = getTextComponent(component);
    if (textComponent != null) {
        textComponent.cut();
    }//from   ww  w. jav a 2 s . c  o m
}

From source file:net.sf.jabref.gui.keyboard.EmacsKeyBindings.java

private static void doCopyOrCut(JTextComponent jtc, boolean copy) {
    if (jtc != null) {
        int caretPosition = jtc.getCaretPosition();
        String text = jtc.getSelectedText();
        if (text != null) {
            // user has manually marked a text without using CTRL+W
            // we obey that selection and copy it.
        } else if (SetMarkCommandAction.isMarked(jtc)) {
            int beginPos = caretPosition;
            int endPos = SetMarkCommandAction.getCaretPosition();
            if (beginPos > endPos) {
                int tmp = endPos;
                endPos = beginPos;/* w  w  w  .  jav a2  s .c  om*/
                beginPos = tmp;
            }
            jtc.select(beginPos, endPos);
            SetMarkCommandAction.reset();
        }
        text = jtc.getSelectedText();
        if (text == null) {
            jtc.getToolkit().beep();
        } else {
            if (copy) {
                jtc.copy();
                // clear the selection
                jtc.select(caretPosition, caretPosition);
            } else {
                int newCaretPos = jtc.getSelectionStart();
                jtc.cut();
                // put the cursor to the beginning of the text to cut
                jtc.setCaretPosition(newCaretPos);
            }
            KillRing.getInstance().add(text);
        }
    }
}