Java Swing How to - Paste clipboard to JTextArea








Question

We would like to know how to paste clipboard to JTextArea.

Answer

// ww w. j av a 2 s .  com
import java.awt.Container;
import java.awt.GridLayout;

import javax.swing.JFrame;
import javax.swing.JTextArea;

public class Main {
    public static void main(String args[]) {
        JFrame frame = new JFrame();
        Container content = frame.getContentPane();

        content.setLayout(new GridLayout(0, 2));

        JTextArea leftTextArea = new JTextArea();
        content.add(leftTextArea);
        leftTextArea.paste();


        frame.setSize(250, 150);
        frame.setVisible(true);
    }
}