Example usage for javax.swing.text JTextComponent copy

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

Introduction

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

Prototype

public void copy() 

Source Link

Document

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

Usage

From source file:Main.java

static void dndCopy(final Component component) {
    final JTextComponent textComponent = getTextComponent(component);
    if (textComponent != null) {
        textComponent.copy();
    }/* w  w  w. j  a  v  a 2  s.com*/
}

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;/*from   w  ww  .j av  a 2  s.com*/
                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);
        }
    }
}

From source file:net.java.sip.communicator.impl.gui.main.chat.ChatPanel.java

/**
 * Copies either the selected write area content or the selected
 * conversation panel content to the clipboard.
 *//*  w w w  . ja v  a2s  .  co m*/
public void copy() {
    JTextComponent textPane = this.conversationPanel.getChatTextPane();

    if (textPane.getSelectedText() == null)
        textPane = this.writeMessagePanel.getEditorPane();

    textPane.copy();
}