Portapapeles Clipboard
StringSelection selection = new StringSelection(theString);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, selection);
package Clipboard;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.util.ArrayList;
import java.util.List;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Omar
*/
public class ClipBoardUtils {
public static List<String> getPortapapelesList() throws Exception {
String cadena = "";
List<String> lista = new ArrayList();
try {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable transferable = clipboard.getContents(null);
if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
cadena = (String) transferable.getTransferData(DataFlavor.stringFlavor);
}
String[] cadenas = cadena.split("\n");
for (int i = 0; i < cadenas.length; i++) {
lista.add(cadenas[i]);
}
} catch (Exception exception) {
String strError = "Error al obtener los datos del portapapeles";
throw new Exception(strError);
}
return lista;
}
public static String getPortapapeles() throws Exception {
String cadena = "";
try {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable transferable = clipboard.getContents(null);
if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
cadena = (String) transferable.getTransferData(DataFlavor.stringFlavor);
}
} catch (Exception exception) {
String strError = "Error al obtener los datos del portapapeles";
throw new Exception(strError);
}
return cadena;
}
}