public static String getOsName() {
System.getProperty("os.name");
}
Check operator system is Windows?
public static boolean isWindows() {
return getOsName().startsWith("Windows");
}
Get text from clipboard.
public static String getTextFromClipBoard() {
String text = "";
try {
text = (String) Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor);
return text;
} catch (UnsupportedFlavorException | IOException ex) {
Logger.getLogger(Utilities.class.getName()).log(Level.SEVERE, null, ex);
}
return text;
}
Set text to clipboard.
public static void setTextToClipBoard(String value) {
StringSelection text = new StringSelection(value);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(text, text);
}
0 comments:
Post a Comment