java - How do you add keyboard commands to a preexisting javafx scene? -


i have been trying find out how add keyboard commands preexisting javafx scene , can not seem find answer anywhere. want have keyboard method run key pressed. add keyboard commands/controls to.

    import javafx.application.application;     import javafx.fxml.fxmlloader;     import javafx.scene.parent;     import javafx.scene.scene;     import javafx.stage.stage;       public class main extends application { public void start(stage primarystage) {     try {         parent root =    fxmlloader.load(getclass().getresource("/fxml/main.fxml"));         scene scene = new scene(root,600,400);         scene.getstylesheets().add(getclass().getresource("application.css").toexternalform());         primarystage.setresizable(false);         primarystage.setscene(scene);         primarystage.settitle("keyboard test app");         primarystage.show();     } catch(exception e) {         e.printstacktrace();     } }  public static void main(string[] args) {     launch(args); } public void key(){  } } 

this help, thanks.

please go through documentation carefully, full of examples !

as matt has suggested must go through handling javafx events section carefully.

if looking example must try keyboardexample

n.b. if facing issues trying implement it, please post code have tried !


Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -