Tuesday 15 March 2011

java - Switching scene in javaFX -


I have a problem while trying to close the current problem and when the menu item is selected, open another view. My main step is coded down:

  Public Zero Start (Stage Primary Stage) throws exceptions {primaryStage.setTitle ("Shop Management"); Panel myPane = (panel) FXMLLoader.load (getClass (). GetResource ("createProduct.fxml")); View myScene = new view (myPane); PrimaryStage.setScene (myScene); PrimaryStage.show (); }   

then create PRODUCT.fxml, when clicked on menuItem, then it will execute it:

  Public Zero Gotkutriat Category (Action Event Event) throws IOException {stage stage = new phase (); Stage.setTitle ("Shop Management"); Pane myPane = faucet; MyPane = FXMLLoader.load (getClass (). GetResource ("createcategory.fxml")); Visual view = new view (myPane); Stage.setScene (view); stage show(); }   

It opens createcategory.fxml However, as the back panel is created, the more productive. FMMM does not stop I know that to do something like this is called stage.close (), but I do not know when I am going through the main right when I start it. I wonder how I should fix it.

Thanks in advance.

You have to make some changes to the start method, such as ..

  Public Zero Start (Stage Primary Stage) throws exceptions {primaryStage.setTitle ("Shop Management"); FXMLLoader myLoader = new FXML loader (getClass (.) GetResource ("createProduct.fxml")); Panel myPane = (panel) myLoader.load (); CreateProductController Controller = (CreateProductController) myLoader.getController (); Controller.setPrevStage (primaryStage); View myScene = new view (myPane); PrimaryStage.setScene (myScene); PrimaryStage.show (); }   

and will be your CreateProductController.java,

  public class CreateProductController applied Initializable {Stage prevStage; Public Zero Setprovvast (Stage Stage) {this.prevStage = stage; } @ Override Public blank Initialization (URL Location, Resourcebundal Resources) {Personal Person with Goto Curettage Category (Action Event Event) throws IOException {Stage Stage = New Stage (); Stage.setTitle ("Shop Management"); Pane myPane = faucet; MyPane = FXMLLoader.load (getClass (). GetResource ("createcategory.fxml")); Visual view = new view (myPane); Stage.setScene (view); PrevStage.close (); stage show(); }}    

No comments:

Post a Comment