Skip to content

Codes #229

@siddharthrgade21-a11y

Description

@siddharthrgade21-a11y

import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;

public class ClipboardCopy {
public static void main(String[] args) {
String textToCopy = "Hello from Advanced Java!";

    // Get the system clipboard
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    
    // Wrap the string in a StringSelection object
    StringSelection selection = new StringSelection(textToCopy);
    
    // Set the clipboard contents
    clipboard.setContents(selection, null);
    
    System.out.println("Text copied to clipboard successfully!");
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions