4

I'm trying to create link-like label in scala. But no mouse events works for me. How are they supposed to work?

class Hyperlink extends Label{
text = "hyperlink"
reactions += {
    case MouseClicked(_,_,_,_,_) =>
        println("mouse clicked")}}

I put this in some panel and click over the label like a pro minesweeper player... and nothing shows up in console. Why?

ryskajakub
  • 6,351
  • 8
  • 45
  • 75
  • See http://stackoverflow.com/questions/938437/scala-swing-event-framework-where-do-i-add-my-reactors – Rex Kerr Mar 25 '10 at 02:27

2 Answers2

5

You need to listenTo the relevant thing, something like:

listenTo(this.mouse.clicks)

Edit: since 2.8.0 Mouse is deprecated, use mouse instead

Paweł Prażak
  • 3,091
  • 1
  • 27
  • 42
oxbow_lakes
  • 133,303
  • 56
  • 317
  • 449
  • pretty hard to find this in the Api. There should be some reference from classes that extend Component, I think – ryskajakub Mar 25 '10 at 18:34
2

Maybe this should have been a comment to the previous answer, but due to my rep, i cant add comments.

this.Mouse is deprecated and this.mouse should be used instead. Also, this might be a good resource: http://www.scala-lang.org/sid/8

Andreas Vinter-Hviid
  • 1,482
  • 1
  • 11
  • 27