I have written a simple scala swing application, with a text field and a button. Whenever user clicks on the button, the content gets copied to the clipboard. But, as soon as the application is closed, the clipboard content is lost. Why ? Is there a way to get around this ?
This is my source code :
package com.loloof64.scalatest
import java.awt.Dimension
import java.awt.Toolkit
import java.awt.datatransfer.Clipboard
import java.awt.datatransfer.StringSelection
import java.awt.datatransfer.Transferable
import scala.swing.BoxPanel
import scala.swing.Button
import scala.swing.MainFrame
import scala.swing.SimpleSwingApplication
import scala.swing.TextField
import scala.swing.Orientation
import scala.swing.event.ButtonClicked
object ClipboardCopyTest extends SimpleSwingApplication {
def writeToClipboard(str:String) {
val clipboard:Clipboard = Toolkit.getDefaultToolkit().getSystemClipboard()
val transferData:Transferable = new StringSelection(str)
clipboard.setContents(transferData, null)
}
override def top = new MainFrame {
val textfield = new TextField(60)
val button = new Button("Copy to clipboard")
contents = new BoxPanel(Orientation.Vertical){
contents += (textfield, button)
listenTo(button)
reactions += {
case _:ButtonClicked => writeToClipboard(textfield.text)
}
}
val prefSize = new Dimension(300,200)
override def size = prefSize
}
}
helps are welcome
i am under ubuntu 13.10 64 bits and I have scala 2.10.3