将信息复制到粘贴板, 以供后续使用.
初始化一个粘贴板实例, 获得系统粘贴板, 将信息加入到粘贴板中.
private Clipboard clipboard; //定义一个粘贴板实例;
buttonCopyToClipBoard.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { clipboard = getToolkit().getSystemClipboard(); //获得系统粘贴板 StringSelection textInfoSelected = new StringSelection(textInfo.getText()); //建立一个粘贴板内容实例. clipboard.setContents(textInfoSelected, null); //将textInfoSelected加入到粘贴板中; labelInfo.setText("The output message has copied to clipboard."); } }//end of calss );
点击CopytoClipBoard按钮后, 将output信息复制到粘贴板, 并在Info中提示复制成功.
// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.