1

it's probably really easy to solve but since I'm really new to scala I even don't know what I don't know.

I have to write a simple application that rewrites input text to output text field after 'Enter' key is hit.

object Main extends SimpleSwingApplication {

def top = new MainFrame {
  title = "Text Fields"
  preferredSize = new Dimension(200, 90)
  val inText = new TextField(10)
  val outText = new TextField(10)
  outText.editable = false
  val inLabel = new Label("input")
  val outLabel = new Label("output")
  inText.listenTo(inText.keys)
  inText.reactions += {
    case EditDone(e) => println("aaaa") ; outText.text = e.text
  }
  contents = new FlowPanel(){ 
    contents += inLabel
    contents += inText
    contents += outLabel
    contents += outText

  }
}

}

the EditDone event does not fire up for some reason. The KeyPressed event works as it should end I know I could check if it's 'enter' key but since there is special event for my case I wish I could use it.

TrN
  • 1,230
  • 2
  • 17
  • 32

1 Answers1

2

Ok I figured it out -

the listenTo method argument has to be component that we want to listen.

So inText text field has to listen to ... it self.

def top = new MainFrame {
  title = "Text Fields"
  preferredSize = new Dimension(200, 90)
  val inText = new TextField(10)
  val outText = new TextField(10)
  outText.editable = false
  val inLabel = new Label("input")
  val outLabel = new Label("output")
  inText.listenTo(inText)   //Changed from inText.keys to inText
  inText.reactions += {
    case EditDone(e) => println("aaaa") ; outText.text = e.text
  }
  contents = new FlowPanel(){ 
    contents += inLabel
    contents += inText
    contents += outLabel
    contents += outText

  }
}
TrN
  • 1,230
  • 2
  • 17
  • 32
  • Ok, but I have to wait 2 days because of StackOverflow policy. But I'll keep it in mind. – TrN Jan 27 '14 at 20:37