Skip to main content

jfx key binding.

2 replies [Last post]
dhruva023
Offline
Joined: 2007-09-26

I just started to learn jfx.

I was wondering how can i bind button with key.

such as if I press "B"
It would say "You pressed B"

thanks.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
alexsch
Offline
Joined: 2007-07-12

You need to define [b]onKeyTyped [/b]operation and set [b]focusable [/b]attribute for Widget element:

[code]
import javafx.ui.*;
import java.lang.System;

Frame{
width: 100
height: 100
title: "Example"
content: BorderPanel{
center: Label {
text: "Press a key."
}

onKeyTyped: operation(event:KeyEvent){
MessageDialog{
title: "Message"
message: "You pressed '{event.keyChar}'"
visible: true
}
}
focusable: true
}
visible: true
}

[/code]

dhruva023
Offline
Joined: 2007-09-26

thanks