本文整理了Java中java.awt.Toolkit.getSystemClipboard()
方法的一些代码示例,展示了Toolkit.getSystemClipboard()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Toolkit.getSystemClipboard()
方法的具体详情如下:
包路径:java.awt.Toolkit
类名称:Toolkit
方法名:getSystemClipboard
暂无
代码示例来源:origin: libgdx/libgdx
@Override
public void setContents (String content) {
try {
StringSelection stringSelection = new StringSelection(content);
java.awt.datatransfer.Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(stringSelection, this);
} catch (Exception ignored) { // Ignore JDK crashes sorting data flavors.
}
}
代码示例来源:origin: looly/hutool
/**
* 获取系统剪贴板
*
* @return {@link Clipboard}
*/
public static Clipboard getClipboard() {
return Toolkit.getDefaultToolkit().getSystemClipboard();
}
代码示例来源:origin: plantuml/plantuml
private void setClipboardImage(BufferedImage image) {
final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(new ImageSelection(image), null);
}
代码示例来源:origin: nodebox/nodebox
public void actionPerformed(ActionEvent actionEvent) {
Clipboard clipboard = getToolkit().getSystemClipboard();
StringSelection ss = new StringSelection(log);
clipboard.setContents(ss, ExceptionDialog.this);
}
});
代码示例来源:origin: bobbylight/RSyntaxTextArea
/**
* Copies the currently selected text to the system clipboard, with
* any necessary style information (font, foreground color and background
* color). Does nothing for {@code null} or empty selections.
*
* @see #copyAsStyledText(Theme)
*/
public void copyAsStyledText() {
int selStart = getSelectionStart();
int selEnd = getSelectionEnd();
if (selStart==selEnd) {
return;
}
// Get the selection as HTML
String html = HtmlUtil.getTextAsHtml(this, selStart, selEnd);
// Get the selection as RTF
byte[] rtfBytes = getTextAsRtf(selStart, selEnd);
// Set the system clipboard contents to the RTF selection.
StyledTextTransferable contents = new StyledTextTransferable(html, rtfBytes);
Clipboard cb = getToolkit().getSystemClipboard();
try {
cb.setContents(contents, null);
} catch (IllegalStateException ise) {
UIManager.getLookAndFeel().provideErrorFeedback(null);
}
}
代码示例来源:origin: libgdx/libgdx
@Override
public void setContents (String content) {
try {
StringSelection stringSelection = new StringSelection(content);
java.awt.datatransfer.Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(stringSelection, this);
} catch (Exception ignored) { // Ignore JDK crashes sorting data flavors.
}
}
代码示例来源:origin: looly/hutool
/**
* 获取系统剪贴板
*
* @return {@link Clipboard}
*/
public static Clipboard getClipboard() {
return Toolkit.getDefaultToolkit().getSystemClipboard();
}
代码示例来源:origin: plantuml/plantuml
private void copy() {
final GeneratedImage generatedImage = simpleLine2.getGeneratedImage();
if (generatedImage == null) {
return;
}
final File png = generatedImage.getPngFile();
final Image image = Toolkit.getDefaultToolkit().createImage(png.getAbsolutePath());
final ImageSelection imgSel = new ImageSelection(image);
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(imgSel, null);
}
代码示例来源:origin: skylot/jadx
public static void setClipboardString(String text) {
try {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable transferable = new StringSelection(text);
clipboard.setContents(transferable, null);
LOG.debug("String '{}' copied to clipboard", text);
} catch (Exception e) {
LOG.error("Failed copy string '{}' to clipboard", text, e);
}
}
}
代码示例来源:origin: libgdx/libgdx
@Override
public String getContents () {
try {
java.awt.datatransfer.Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable contents = clipboard.getContents(null);
if (contents != null) {
if (contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
try {
return (String)contents.getTransferData(DataFlavor.stringFlavor);
} catch (Exception ex) {
}
}
if (contents.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
try {
List<File> files = (List)contents.getTransferData(DataFlavor.javaFileListFlavor);
StringBuilder buffer = new StringBuilder(128);
for (int i = 0, n = files.size(); i < n; i++) {
if (buffer.length() > 0) buffer.append('\n');
buffer.append(files.get(i).toString());
}
return buffer.toString();
} catch (RuntimeException ex) {
}
}
}
} catch (Exception ignored) { // Ignore JDK crashes sorting data flavors.
}
return "";
}
代码示例来源:origin: stackoverflow.com
try {
Robot robot = new Robot();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle screen = new Rectangle( screenSize );
BufferedImage i = robot.createScreenCapture( screen );
TransferableImage trans = new TransferableImage( i );
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
c.setContents( trans, this );
代码示例来源:origin: MovingBlocks/Terasology
/**
* Set the contents of the clipboard to a given value.
*
* @param str The new value of the clipboard contents
*/
protected void setClipboardContents(String str) {
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(str), null);
}
代码示例来源:origin: libgdx/libgdx
@Override
public String getContents () {
try {
java.awt.datatransfer.Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable contents = clipboard.getContents(null);
if (contents != null) {
if (contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
try {
return (String)contents.getTransferData(DataFlavor.stringFlavor);
} catch (Exception ex) {
}
}
if (contents.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
try {
List<File> files = (List)contents.getTransferData(DataFlavor.javaFileListFlavor);
StringBuilder buffer = new StringBuilder(128);
for (int i = 0, n = files.size(); i < n; i++) {
if (buffer.length() > 0) buffer.append('\n');
buffer.append(files.get(i).toString());
}
return buffer.toString();
} catch (RuntimeException ex) {
}
}
}
} catch (Exception ignored) { // Ignore JDK crashes sorting data flavors.
}
return "";
}
代码示例来源:origin: guoguibing/librec
public static void toClipboard(String data) throws Exception {
Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
StringSelection ss = new StringSelection(data);
cb.setContents(ss, ss);
}
代码示例来源:origin: stackoverflow.com
import java.awt.HeadlessException;
import java.awt.Toolkit;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
String data = (String) Toolkit.getDefaultToolkit()
.getSystemClipboard().getData(DataFlavor.stringFlavor);
代码示例来源:origin: bonnyfone/vectalign
public static void copyToClipboard(String data){
Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
clpbrd.setContents(new StringSelection(data), null);
}
代码示例来源:origin: MovingBlocks/Terasology
@Override
public String getClipboardContentsAsString() {
return AccessController.doPrivileged(
(PrivilegedAction<String>) () -> {
Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
try {
if (t != null) {
return (String) t.getTransferData(DataFlavor.stringFlavor);
}
} catch (UnsupportedFlavorException | IOException e) {
return null;
}
return null;
});
}
代码示例来源:origin: JetBrains/ideavim
/**
* Puts the supplied text into the system clipboard
*
* @param text The text to add to the clipboard
*/
public static void setClipboardText(String text) {
try {
Clipboard board = Toolkit.getDefaultToolkit().getSystemClipboard();
StringSelection data = new StringSelection(text);
board.setContents(data, null);
}
catch (HeadlessException e) {
// ignore
}
}
}
代码示例来源:origin: MovingBlocks/Terasology
/**
* Get the current clipboard contents.
*
* @return The string currently in the clipboard
*/
protected String getClipboardContents() {
Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
try {
if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
return (String) t.getTransferData(DataFlavor.stringFlavor);
}
} catch (UnsupportedFlavorException | IOException e) {
logger.warn("Failed to get data from clipboard", e);
}
return "";
}
代码示例来源:origin: igniterealtime/Smack
@Override
public void actionPerformed(ActionEvent e) {
// Get the clipboard
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
// Set the sent text as the new content of the clipboard
clipboard.setContents(new StringSelection(sentText1.getText()), null);
}
});
内容来源于网络,如有侵权,请联系作者删除!