简体   繁体   中英

JavaFX set listview to be editable

I am kinda new to JavaFX, so maybe this is very easy to do. I have a ListView<String> , and what I want is that I can have a button which when pressed, basically turns the selected String into a sort of text field in which you can edit the name of that specific item. I hope it is clear what I want. I already tried list.setEditable(true) , but that didn't change anything.

In addition to making the ListView editable you also need to make sure to use a cellFactory providing editable cells:

list.setEditable(true);
list.setCellFactory(TextFieldListCell.forListView());

This way you can start a edit on a double click of a cell.

First, I'd use in this case a VBox filled with the TextFields. Those TextFields should have the editable property set to false. When you click on the button, you can call:

    ((TextField)vbox.getChildren().get(numberofTextFieldInList)).setEditable(true);

and now it should be editable. If you want the TextFields to look like Strings when not being editable, I would modify the aesthetic properties.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM