javafx 2 - How do I make a java class that inherits from another one which is loading an fxml file -


i have custom interface created in scene builder , want reuse in variation created child class. problem seems won't inherit methods marked @fxml. there way extend class loads fxml instead of copying entire class?

example parent class:

public class browser extends stackpane implements initializable {  public browser() { fxmlloader fxmlloader = new fxmlloader(getclass().getresource("fxml/browser.fxml")); fxmlloader.setroot(this); fxmlloader.setcontroller(this); try { fxmlloader.load(); } catch (ioexception exception) { throw new runtimeexception(exception); }  @override public void initialize(url url, resourcebundle rb) { }  // adds new tab. @fxml private void addtab(actionevent event) {     browsertab tab = new browsertab();     tab.getengine().load(initialtab.getaddress());     if (tabs.gettabs().size() >= tabmax + 1) {         baseapp.shownotify("you may open maximum of " + tabmax + " tabs.");     } else {         tabs.gettabs().add(tabs.gettabs().size() - 1, tab.tab);     } } } 

example child class:

public class adbrowser extends browser {  public adbrowser() {     fxmlloader fxmlloader = new fxmlloader(getclass().getresource("fxml/adbrowser.fxml"));     fxmlloader.setroot(this);     fxmlloader.setcontroller(this);     try {         fxmlloader.load();     } catch (ioexception exception) {         throw new runtimeexception(exception);     } }  } 

when try run program instantiating child class , error saying controller method "addtab" not found.

turning comment answer.

i have no experience @ fxml, try broadening access permissions method, e.g. private protected.

code outside class defining private method not allowed call method. frameworks circumvent these restrictions, , perhaps javafx among them. these frameworks might , distinguish based on access privileges given method has.

one reason behind private method name should never cause clash: can have 2 private methods of same name in base class , derived class, , neither knows of other. will not override 1 another. far derived class concerned, method in parent class not exist. since reasonable working principle, makes sense frameworks follow well, if circumvented access restrictions allow them act otherwise.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -