• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Javafx TextField on edit event

 
Sudarshan Deshmukh
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am Trying to use TextField in javafx. The scenario is I have list view populated with specific objects and edit button to edit the object associated with list cell of list view. When I click on edit button it redirects me to a pane with editing feature when I can edit the name of that object and save it using save button. So I have to put validation on save button to make it enable and disable . If I edit the name in text field then it should enable the save button other wise it should remains disabled. I have tried using different methods on text fields as below.

textField.textPorperty.addListener(listener -> {
//Logic to enable disable save button
});
As I am using list view, this listener gives me old value as previously edited object which does not satisfy my condition. I can not use

`textField.focusedProperty().addListener((observableValue, oldValue, newValue) -> {});`
as It does not give me expected behavior.

Can anyone help me to solve this issue?
 
Luis De Bello
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sudarshan,

Why don't you use one key pressed listener in the textfield in order to enable/disable the button?

Regards,
Luis
 
John Damien Smith
Ranch Hand
Posts: 296
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this sample and see if anything in it does what you are looking for.
The sample implements a couple of different methods of providing editing functions.
One is a label, separate text field to edit the label and a save button to copy the edited text to the label (which I think is as you describe in your question).
The other editing method is a toggle button next to a text field which is initially read-only and styled to look like a label. When the button is toggled, the text field becomes editable and styled like a normal text field. Once the editing is complete by the user pressing enter or pressing the toggle button again to de-select it, the text field is styled to look like a label again.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic