• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is there some documentation that shows you a standard way of altering Java code to FXML ?

 
Nikolas Nikolaou
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
Is there some guideline for converting Java code to FXML ?
I mean Is there some set of rules I could learn that would allow me to create the tags and nodes by
Just looking at the original Java code ?
 
John Damien Smith
Ranch Hand
Posts: 296
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No.

The closest resource you will find is studying:
https://docs.oracle.com/javase/8/javafx/api/javafx/fxml/doc-files/introduction_to_fxml.html
Which you have probably already read.

Don't try to write a Java Code => FXML converter, it is not possible to do so for arbitrary Java code.

Java is a general purpose programming language.
FXML is just a declarative markup for generation of objects (usually JavaFX nodes).
As FXML does not, and never will, support all of the functionality of a general Java program, you could never write a converter to convert the complete functionality of the Java program to FXML.

FXML works by using reflection to create instances Java of classes and to call methods on those instances, based upon the definitions supplied in an FXML document.

Generally, for simple object creation and construction (not complex application logic), it is possible to translate that from Java to FXML, though there are no automated tools to do it, you have to do it manually.

The rule of thumb to do so, would be that each new object in Java becomes an element in the FXML and each setter invoked on that object in Java becomes an attribute of the associated element in FXML.
Event handlers, are prefixed with #.
That is a very simplistic outline, but would be enough to convert some basic object instantiations from Java to FXML.

For instance:

Would become:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic