• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

How can I enable a Dialog's button from an event handler method?

 
Bartender
Posts: 390
47
Firefox Browser MySQL Database Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to learn a sprinkling of JavaFx to test the backend code of a personal project I am working on. At the moment I am trying to create a simple login dialog. I want to disable the 'ok' button until all the input fields contain valid data. I have knocked together a little example to demonstrate what I want.

For context, this is how I create the dialog:
and this is the fxml:
My issue is enabling the button once the input it valid. I have another method 'validateInput()' to check if the TextField contains valid data.
I tried creating a field for the DialogPane, but calling lookUpButton(ButtonType.OK) always returns null. I also tried using a Dialog<ButtonType> field and then setting it to the Dialog object I create in buttonClicked(), instead of a local variable:
The field is always null from the validateInput() method, however.

I'm more or less shooting in the dark here. There is a lot to JavaFx which I will have to get to grips with
How can I enable the button from the validateInput() method?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hope you've already found a way to do this, but if not, here it goes:

You need to bind the property of the OK button to a BooleanBinding:

 
Marshal
Posts: 80943
521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
VAR: welcome to the Ranch
 
Bartender
Posts: 337
12
IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I started a more elaborate reply before I saw the age of the first post and realized that the OP is probably an expert by now. I guess 4 years late is better than never! Don't think I was active back then or I'd have definitely replied.

We do need some new blood injected in here, are visitors not posting because it looks inactive?

Thanks for the activity though Victor. Good to see new JFX users around.
reply
    Bookmark Topic Watch Topic
  • New Topic