java - Using custom Controls in fxml -


let's have subclassed default tableview<t> class provided javafx , created class persontableview extends tableview<person>. subclass exists in java code , not use fxml @ all. defines , encapsulates behaviour need person object.

now want use instance of custom class inside of fxml file, use default controls. , problem, don't know how can that, or if / common design decision.

i want encapsulate behaviour specific tableview inside own class, layout should defined in fxml has nothing logic, cosmetics.

i imagine kind of syntax , functionality can found in wpf .net, can use custom classes in markup other control, because xaml , c# more tightly coupled java , fxml.

from current point of view, described cannot done , instead end using small amount of fxml , lot more code, parts layout. example not want use code this:

 anchorpane.setrightanchor(customcontrol, 65.0); 

because believe idea have defined inside fxml.

so question either, how implement described above; or, if uncommon, common, "best-practice" way similar functionality described?

is looking for? works fine me.

package numerictextfield;  import java.util.regex.pattern;  import javafx.scene.control.indexrange; import javafx.scene.control.textfield;  public class numerictextfield extends textfield {      private final pattern intpattern = pattern.compile("[0-9]*");      public numerictextfield(string text) {         super(text);     }     public numerictextfield() {         super();         this.inserttext(0, "");         this.replaceselection("");         this.replacetext(new indexrange(0, 0), "");         this.replacetext(0, 0, "");     }      @override     public void inserttext(int index, string text) {         if (intpattern.matcher(text).matches()) {             super.inserttext(0, text);         }     }      @override     public void replaceselection(string text) {         if (intpattern.matcher(text).matches()) {             super.replaceselection(text);         }     }      @override     public void replacetext(indexrange range, string text) {         if (intpattern.matcher(text).matches()) {             super.replacetext(range, text);         }     }      @override     public void replacetext(int start, int end, string text) {         if (intpattern.matcher(text).matches()) {             super.replacetext(start, end, text);         }     }  } 

and then

<?xml version="1.0" encoding="utf-8"?>  <?import javafx.scene.layout.anchorpane?> <?import numerictextfield.numerictextfield?>  <anchorpane xmlns:fx="http://javafx.com/fxml" >     <numerictextfield text="12345" >         <anchorpane.rightanchor>65.0</anchorpane.rightanchor>     </numerictextfield> </anchorpane> 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -