Java Swing - Clip
package jlib5.swing; import java.awt.Toolkit; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.ClipboardOwner; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.StringSelection; import java.awt.datatransfer.Transferable; public class Clip implements ClipboardOwner { Clipboard clipboard; public Clip() { clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); } @Override public void lostOwnership(Clipboard clipboard, Transferable contents) { } public void putString(String text) { StringSelection contents = new StringSelection(text); clipboard.setContents(contents, this); } public String getString() { Transferable content = clipboard.getContents(this); try { String text = (String) content.getTransferData(DataFlavor.stringFlavor); return text; } catch (Exception e) { e.printStackTrace(); } return null; } }
댓글 없음:
댓글 쓰기