Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CheckBoxes have to be clicked twice before calling ActionEvent

 
Christopher Sheridan
Ranch Hand
Posts: 50
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have methods written to handle the actions for check boxes. This is as far as I've gotten:

When checking a certain category of plant, the ones that are not relevant are supposed to disappear from view. When they are un-checked, they reappear. The problem is that I have to initially click a CheckBox twice to begin the process. The other boxes and buttons need to disappear on the first click. It's almost like the annoying mistake we make sometimes with the Scanner class and having to fire an extra input.nextLine() so the first input is not consumed. At least that's what it reminds me of.

Can someone help me out? I don't understand why this is happening.

Note: I included two screenshots of the GUI so you know what I'm doing.

Here is the segment of code:


Here is a line in FXML if it's relevant:



I am using SceneBuilder 2.0 also.
BeforeClicked.png
[Thumbnail for BeforeClicked.png]
Before box is checked. Buttons not visible.
AfterClicked.png
[Thumbnail for AfterClicked.png]
After box is checked. Buttons now visible.
 
A.J. Côté
Ranch Hand
Posts: 417
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Maybe the first ignored click just gains focus on the component. Try to programmatically give focus to the component in advance to see what happens.

Just my 2 cents, it is the first idea that crossed my mind.
 
Christopher Sheridan
Ranch Hand
Posts: 50
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know how to do that, or what that method does. I'm very new to JavaFX.
 
Christopher Sheridan
Ranch Hand
Posts: 50
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, I wrote print statements for all of my buttons to see what was going on via the console, and EVERY button has to be clicked twice.

So, I have that bug, and one more bug:

I have my radio buttons set as boolean values. If it is checked, it should print true. If it is not checked, it should print false.

I'm so close to being done with this. At least I've come this far, but this bug is kind of driving me batty.

Take a look:
BeforeAddClick.png
[Thumbnail for BeforeAddClick.png]
As you can see, I selected both radio buttons, which should print TRUE.
AfterAddClick.png
[Thumbnail for AfterAddClick.png]
However, they return FALSE no matter what.
 
John Damien Smith
Ranch Hand
Posts: 299
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not a focus related issue. Your code here has the same issue as your code from an earlier question:

http://www.coderanch.com/t/657771/JavaFX/java/user-input-TextField-display-ListView

Don't call setOnAction from an event handler, all you do when you do that is wire up the behavior of your buttons AFTER they have been clicked once.
Get rid of the buttonAction Event handler and move all of the contents of it to your controller's initialize method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic