This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Re: Re: swing.TextField generates EditDone event when losing focus

4 replies
nikolaj
Joined: 2008-11-11,
User offline. Last seen 3 years 4 weeks ago.


On Sun, Nov 22, 2009 at 6:00 PM, Ken Bloom <kbloom [at] gmail [dot] com> wrote:
On Wed, 18 Nov 2009 18:52:52 +0100, nikolaj lindberg wrote:

[...]
> How do I know what EditDone events are generated by typing <enter> and
> not by the TextField component losing focus? Any hints are welcome!

You probably want a KeyTyped event to look specifically for the Enter key.



Hi Ken,

yes, I would love one of those, but the Enter key seems to only generate the EditDone event (and not a ValueChanged event, like when entering an "ordinary" character).

/nikolaj

 


--
Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu/~kbloom1/


Ingo Maier
Joined: 2009-11-23,
User offline. Last seen 42 years 45 weeks ago.
Re: Re: swing.TextField generates EditDone event when losing f
Ken was referring to the KeyTyped event, not the ValueChanged event. The latter won't trigger since typing enter does not change the text field's contents.   Hope this helps, Ingo

On Sun, Nov 22, 2009 at 9:16 AM, nikolaj lindberg <nikolaj [dot] lindberg [at] gmail [dot] com> wrote:


On Sun, Nov 22, 2009 at 6:00 PM, Ken Bloom <kbloom [at] gmail [dot] com> wrote:
On Wed, 18 Nov 2009 18:52:52 +0100, nikolaj lindberg wrote:

[...]
> How do I know what EditDone events are generated by typing <enter> and
> not by the TextField component losing focus? Any hints are welcome!

You probably want a KeyTyped event to look specifically for the Enter key.



Hi Ken,

yes, I would love one of those, but the Enter key seems to only generate the EditDone event (and not a ValueChanged event, like when entering an "ordinary" character).

/nikolaj

 


--
Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu/~kbloom1/



nikolaj
Joined: 2008-11-11,
User offline. Last seen 3 years 4 weeks ago.
Re: Re: swing.TextField generates EditDone event when losing f

On Mon, Nov 23, 2009 at 7:40 PM, Ingo Maier <ingoem [at] googlemail [dot] com> wrote:
Ken was referring to the KeyTyped event, not the ValueChanged event. The latter won't trigger since typing enter does not change the text field's contents.   Hope this helps, Ingo


Ingo,

thanks.

Hmm... I still don't see any KeyTyped events generated by the TextField.
I must be doing something really stupid, but I just get those ValueChanged events.

When I run the code below (Scala 2.8), and input characters into the TextField, all that's printed are ValueChanged events.

What am I doing wrong, and how do I catch those KeyTyped events? (I'm beginning to fear that I'm missing some fundamental clue here...)

/nikolaj


//------------------------------------------------------------------
import swing._
import event._

object tst extends MainFrame {

  val textField = new TextField(20)
  contents = textField
  listenTo(textField)
  reactions += {case e =>
    println(e)
    println()
  }

  pack
  visible = true

  def main(args: Array[String]) {}
}





 
On Sun, Nov 22, 2009 at 9:16 AM, nikolaj lindberg <nikolaj [dot] lindberg [at] gmail [dot] com> wrote:


On Sun, Nov 22, 2009 at 6:00 PM, Ken Bloom <kbloom [at] gmail [dot] com> wrote:
On Wed, 18 Nov 2009 18:52:52 +0100, nikolaj lindberg wrote:

[...]
> How do I know what EditDone events are generated by typing <enter> and
> not by the TextField component losing focus? Any hints are welcome!

You probably want a KeyTyped event to look specifically for the Enter key.



Hi Ken,

yes, I would love one of those, but the Enter key seems to only generate the EditDone event (and not a ValueChanged event, like when entering an "ordinary" character).

/nikolaj

 


--
Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu/~kbloom1/




Ingo Maier
Joined: 2009-11-23,
User offline. Last seen 42 years 45 weeks ago.
Re: Re: swing.TextField generates EditDone event when losing f
You need to listenTo(textField.keys). This is one of the unfortunate points of the publisher/reactor design. In order to make things more efficient, components do not publish all events themselves. See Component.mouse, Component.keys and ListView.selection for examples. Also look into the test package which is part of the scala.swing distribution, do a grep, and you may find what you need. For your specific case, there is the painting demo (not in 2.7.x I believe but in 2.8/trunk) which also reacts to key events.   Ingo

On Mon, Nov 23, 2009 at 12:33 PM, nikolaj lindberg <nikolaj [dot] lindberg [at] gmail [dot] com> wrote:

On Mon, Nov 23, 2009 at 7:40 PM, Ingo Maier <ingoem [at] googlemail [dot] com> wrote:
Ken was referring to the KeyTyped event, not the ValueChanged event. The latter won't trigger since typing enter does not change the text field's contents.   Hope this helps, Ingo


Ingo,

thanks.

Hmm... I still don't see any KeyTyped events generated by the TextField.
I must be doing something really stupid, but I just get those ValueChanged events.

When I run the code below (Scala 2.8), and input characters into the TextField, all that's printed are ValueChanged events.

What am I doing wrong, and how do I catch those KeyTyped events? (I'm beginning to fear that I'm missing some fundamental clue here...)

/nikolaj


//------------------------------------------------------------------
import swing._
import event._

object tst extends MainFrame {

  val textField = new TextField(20)
  contents = textField
  listenTo(textField)
  reactions += {case e =>
    println(e)
    println()
  }

  pack
  visible = true

  def main(args: Array[String]) {}
}





 
On Sun, Nov 22, 2009 at 9:16 AM, nikolaj lindberg <nikolaj [dot] lindberg [at] gmail [dot] com> wrote:


On Sun, Nov 22, 2009 at 6:00 PM, Ken Bloom <kbloom [at] gmail [dot] com> wrote:
On Wed, 18 Nov 2009 18:52:52 +0100, nikolaj lindberg wrote:

[...]
> How do I know what EditDone events are generated by typing <enter> and
> not by the TextField component losing focus? Any hints are welcome!

You probably want a KeyTyped event to look specifically for the Enter key.



Hi Ken,

yes, I would love one of those, but the Enter key seems to only generate the EditDone event (and not a ValueChanged event, like when entering an "ordinary" character).

/nikolaj

 


--
Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu/~kbloom1/





nikolaj
Joined: 2008-11-11,
User offline. Last seen 3 years 4 weeks ago.
Re: Re: swing.TextField generates EditDone event when losing f


On Tue, Nov 24, 2009 at 12:22 AM, Ingo Maier <ingoem [at] googlemail [dot] com> wrote:
You need to listenTo(textField.keys). This is one of the unfortunate points of the publisher/reactor design. In order to make things more efficient, components do not publish all events themselves. See Component.mouse, Component.keys and ListView.selection for examples. Also look into the test package which is part of the scala.swing distribution, do a grep, and you may find what you need. For your specific case, there is the painting demo (not in 2.7.x I believe but in 2.8/trunk) which also reacts to key events.   Ingo



Oh, great, thanks. Now I get it, at last.

(I settled for something like this:
    import Key._
    reactions += {case KeyPressed(_, Enter, _, _) =>
    ...

It also works with
   reactions += {case KeyTyped(_, '\n', _, _) =>
   ...
)

The TextField.keys field was a bit tricky to find, even after being told about it. Almost :)

I still find it odd that you get an EditDone event when TextField loses focus, but I guess there is some clever reason for this.

Again, thanks.
/nikolaj



 
On Mon, Nov 23, 2009 at 12:33 PM, nikolaj lindberg <nikolaj [dot] lindberg [at] gmail [dot] com> wrote:

On Mon, Nov 23, 2009 at 7:40 PM, Ingo Maier <ingoem [at] googlemail [dot] com> wrote:
Ken was referring to the KeyTyped event, not the ValueChanged event. The latter won't trigger since typing enter does not change the text field's contents.   Hope this helps, Ingo


Ingo,

thanks.

Hmm... I still don't see any KeyTyped events generated by the TextField.
I must be doing something really stupid, but I just get those ValueChanged events.

When I run the code below (Scala 2.8), and input characters into the TextField, all that's printed are ValueChanged events.

What am I doing wrong, and how do I catch those KeyTyped events? (I'm beginning to fear that I'm missing some fundamental clue here...)

/nikolaj


//------------------------------------------------------------------
import swing._
import event._

object tst extends MainFrame {

  val textField = new TextField(20)
  contents = textField
  listenTo(textField)
  reactions += {case e =>
    println(e)
    println()
  }

  pack
  visible = true

  def main(args: Array[String]) {}
}





 
On Sun, Nov 22, 2009 at 9:16 AM, nikolaj lindberg <nikolaj [dot] lindberg [at] gmail [dot] com> wrote:


On Sun, Nov 22, 2009 at 6:00 PM, Ken Bloom <kbloom [at] gmail [dot] com> wrote:
On Wed, 18 Nov 2009 18:52:52 +0100, nikolaj lindberg wrote:

[...]
> How do I know what EditDone events are generated by typing <enter> and
> not by the TextField component losing focus? Any hints are welcome!

You probably want a KeyTyped event to look specifically for the Enter key.



Hi Ken,

yes, I would love one of those, but the Enter key seems to only generate the EditDone event (and not a ValueChanged event, like when entering an "ordinary" character).

/nikolaj

 


--
Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu/~kbloom1/






Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland