Win a copy of Raising Young Coders: A Parent’s Guide to Teaching Programming at Home this week in the General Computing forum!
Forums Login/signup

Javafx TextField on edit event

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
Hi Sudarshan,

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

Regards,
Luis
+Pie Number of slices to send: Send
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.


reply
reply
This thread has been viewed 20533 times.
Similar Threads
JavaFX TextArea - fit height to content
Focus Listener for JavaFX Nodes
ToggleButton vs RadioButton
JavaFx tableview mouse scroll bug
text filed and button validation
More...

All times above are in ranch (not your local) time.
The current ranch time is
Jun 27, 2025 08:34:23.