- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to paste clipboard text to JTextArea
To paste clopboard text to JTextArea, use tha paste () method. Let’s say the following is our text area −
JTextArea textArea = new JTextArea("");
Now, paste the clipboard text −
textArea.paste();
Note − Let’s say our clipboard text is “This is clipboard text that got inserted in the text area”.
The following is an example to paste clipboard text to JTextArea −
Example
package my; import java.awt.Container; import java.awt.GridLayout; import javax.swing.*; public class SwingDemo { SwingDemo() { JFrame frame = new JFrame("Demo"); JTextArea textArea = new JTextArea(""); Container c = frame.getContentPane(); c.setLayout(new GridLayout(0, 2)); c.add(textArea); // paste clipboard text textArea.paste(); frame.add(textArea); frame.setSize(550,300); frame.setLayout(new GridLayout(2, 2)); frame.setVisible(true); } public static void main(String args[]) { new SwingDemo (); } }
Output
- Related Articles
- How can I append text to JTextArea in Java?
- Java Program to display the contents in JTextArea
- Java Program to set JTextArea to wrap by word in Java
- How to display a bold text inside the JTextArea in Java?\n
- Copy and paste to your clipboard using the pyperclip module in Python
- How to copy text to the clipboard with JavaScript?
- How can we disable cut, copy and paste functionality of a JTextArea in Java?
- Java Program to replace the first 10 characters in JTextArea
- How to copy text to the clipboard/pasteboard with Swift?
- Program to get JTextArea font information
- Java Program to create JRadioButton from text
- Java Program to format text in JTextPane
- How can we implement line wrap and word wrap text inside a JTextArea in Java?
- Java Program to Append Text to an Existing File
- How to stop copy, paste, and backspace in text widget in tkinter?

Advertisements