Accessing javaFX elements from Java Code (outside controller classes) -


is possible edit/access javafx elements (such buttons, labels, etc.) in java code not controller class?

i have written entire program in java , want make gui in javafx (using scene builder). since entire code written in java classes outside fxml-controller class, possible access elements "labels" inside written classes?

all want use code outside fxml-controller class: label1.settext("something");

so updates on gui.

if not, time-consuming process implement java code in fxml-controller class.

so think solution depends on how safe need information when interfacing fx gui. if ok providing data directly controller, i'd suggest passing data object controller's constructor , storing reference locally. can use getters/setters data object populate gui, or update model.

 public class controller {       private object dataobject;        public controller(object dataobject) {            this.dataobject = dataobject;       }  } 

however, if want protect data, , prevent gui directly modifying or interacting - you'll need use wrapper protects information.

 public class wrapper {       private object dataobject;        public controller(object dataobject) {                 this.dataobject = dataobject;       }        // allowable function call       public object functionone() {            return dataobject.functionone();       }  } 

you need implement functions in wrapper directly needed gui, preventing calls data object think should restricted gui.

your controller becomes:

 public class controller {       private wrapper dataobject;        public controller(wrapper dataobject) {            this.dataobject = dataobject;       }  } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -