javafx - switch scene when clicking on a treeitem -
how switch or load new scene clicking on item of treeview.
here controller
public void initialize(url location, resourcebundle resources) { loaditems(); } @suppresswarnings("unchecked") public void loaditems() { treeitem<string>root=new treeitem<>("root"); treeitem<string> clients=new treeitem<>("clients"); treeitem<string> addclient=new treeitem<>("add client"); treeitem<string> seeclient=new treeitem<>("see clients"); treeitem<string> articles=new treeitem<>("articles"); treeitem<string> devis=new treeitem<>("devis"); root.getchildren().addall(clients,articles,devis); clients.getchildren().addall(addclient,seeclient); root.setexpanded(true); treeview.setroot(root); treeview.setshowroot(false); }
the controller called mainapp.java.
@override public void start(stage primarystage) { this.primarystage=primarystage; mainmenuview(); } public void mainmenuview() { try { fxmlloader loader=new fxmlloader(); loader.setlocation(mainapp.class.getresource("view/menuview.fxml")); anchorpane menuview=(anchorpane)loader.load(); rootview.setcenter(menuview); menuviewcontroller controller = loader.getcontroller(); controller.setmainapp(this); treeloadingeventhandler tree=new treeloadingeventhandler(controller); tree.handle(null); } catch(exception e) { e.printstacktrace(); } } private class treeloadingeventhandler implements eventhandler<actionevent> { private menuviewcontroller controller; treeloadingeventhandler(menuviewcontroller controller) { this.controller = controller; } @override public void handle(actionevent t) { controller.loaditems(); } }
i want load fxml when clicking on item. example, if click on item "add client", fxml called "addclient.fxml" has loaded mainapp.java. thank help.
Comments
Post a Comment