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

Wrong Button Added To Scene?

 
Vince Valentin
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy folks,

Forgive my complete ignorance, but I just decided to start learning JavaFX. I created the basic project and started playing with it, and noticed something funny. When I tried to add a second button, it was placed on top of the old one, which I thought was weird, but the strangest thing happened when I commented out the code to actually add that button to the scene! Here's the code:



As you can see, I commented out the addition of btn2, but left the implementation. I was really just experimenting and seeing what I can do. (The lambda expression was autogenerated for me by NetBeans so I don't know if that has any effect on this.) Basically what happens is if I run the code, the Goodbye World button (btn2) is added and is fully functional!? What's even stranger to me is when I uncomment btn2 and comment out btn1 I get a small button with nothing written on it and no functionality.

If anyone could please explain what's going on here, it would help me immensely in figuring this thing out. If FX is supposed to replace Swing I am going to have to start learning this sooner or later

Thanks in advance!
 
Dennis Grimbergen
Ranch Hand
Posts: 159
IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vince,

Although you don't add button2 to your stackpane, there is a minor bug in your code. At lines 30 and 31 you overwrite the text and eventhandler of button1.
btn should be btn2.
 
Vince Valentin
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You, sir, are the man. Such a stupid mistake lol. Thank you so much
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic