java - Is it possible to append text in the textfield while typing? -


i trying build task manager. trying let user edit task, , program respond command without user pressing enter button.

for example, if have list of tasks:

  1. go school
  2. good day

if user types "edit 2" in text field, program append content of 2nd task @ of input without having press enter button i.e. text field should change edit 2 day. user can modify content.

is possible?

if yes, necessary things need learn?

you can done using textproperty() of textfield , playing around it.

i have created demo :

input

edit 1

output

edit 1 go school

code

import java.util.hashmap; import java.util.map;  import javafx.application.application; import javafx.beans.value.changelistener; import javafx.beans.value.observablevalue; import javafx.scene.scene; import javafx.scene.control.textfield; import javafx.scene.layout.pane; import javafx.stage.stage;  public class textfieldautoappend extends application {      @override     public void start(stage primarystage) throws exception {          map<string, string> mapoftasks = new hashmap<string, string>();         mapoftasks.put("1", "go school");         mapoftasks.put("2", "good day");          pane pane = new pane();         textfield textfield = new textfield();         pane.getchildren().add(textfield);          textfield.textproperty().addlistener(new changelistener<string>() {              @override             public void changed(observablevalue<? extends string> observable,                     string oldvalue, string newvalue) {                 string[] substrings = newvalue.split(" ");                 if(substrings.length ==2){                     if(substrings[0].equalsignorecase("edit") && mapoftasks.keyset().contains(substrings[1])){                         textfield.settext(newvalue + " " + mapoftasks.get(substrings[1]));                     }                 }             }         });          scene scene = new scene(pane, 200, 200);         primarystage.setscene(scene);         primarystage.show();     }      public static void main(string[] args) {         launch(args);     } } 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -