Example usage for javax.swing JTextField paste

List of usage examples for javax.swing JTextField paste

Introduction

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

Prototype

public void paste() 

Source Link

Document

Transfers the contents of the system clipboard into the associated text model.

Usage

From source file:Main.java

public static void main(String args[]) {
    final JTextField textField = new JTextField(15);
    JButton buttonCut = new JButton("Cut");
    JButton buttonPaste = new JButton("Paste");
    JButton buttonCopy = new JButton("Copy");

    JFrame jfrm = new JFrame("Cut, Copy, and Paste");
    jfrm.setLayout(new FlowLayout());
    jfrm.setSize(230, 150);//  w w w.  j a  va  2s .c om
    jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    buttonCut.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent le) {
            textField.cut();
        }
    });

    buttonPaste.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent le) {
            textField.paste();
        }
    });

    buttonCopy.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent le) {
            textField.copy();
        }
    });

    textField.addCaretListener(new CaretListener() {
        public void caretUpdate(CaretEvent ce) {
            System.out.println("All text: " + textField.getText());
            if (textField.getSelectedText() != null)
                System.out.println("Selected text: " + textField.getSelectedText());
            else
                System.out.println("Selected text: ");
        }
    });

    jfrm.add(textField);
    jfrm.add(buttonCut);
    jfrm.add(buttonPaste);
    jfrm.add(buttonCopy);
    jfrm.setVisible(true);
}

From source file:org.zaproxy.zap.extension.openapi.ImportFromUrlDialog.java

public JTextField addContextMenu(final JTextField field) {
    JPopupMenu jPopupMenu = new JPopupMenu();
    String actionName = Constant.messages.getString(MESSAGE_PREFIX + "pasteaction");
    @SuppressWarnings("serial")
    Action pasteAction = new AbstractAction(actionName) {

        public void actionPerformed(ActionEvent e) {
            field.paste();
        }/*from   ww w.ja v a2  s. c  o m*/
    };
    JMenuItem paste = new JMenuItem(pasteAction);
    jPopupMenu.add(paste);
    field.setComponentPopupMenu(jPopupMenu);
    return field;
}