reset password
Author Message
mferras2
Posts: 7
Posted 23:46 Nov 28, 2018 |

Hey all,

I was wondering if having a new pane being brought up by a button action was how anyone tried to designer their GUI, or if that's what Kennan intended. I'm having some difficulty having a pane being brought up by an event handler. For example, my main menu has 6 buttons that allow the user to either add, delete, import etc.. Once a button is clicked the new pane replaces the old one, but cannot return to the main menu pane. Any suggestions or comments welcomed.

 

bsanc115
Posts: 7
Posted 23:56 Nov 28, 2018 |

That's how I'm designing mine, you would have to attach the new pane to a second (new) scene.   Once you have that, all you would need to do is create the event handle for the button that changes the scene.  Ex:  changeSceneButton.setOnMouseClick(e->{

                   primaryStage.setScene(newScene);

}}; 

In order to return to the first scene from your second scene , you would add a button in your second panel that basically runs the same code as the example shown except it sets the first scene rather than the second.  

rgallegos
Posts: 29
Posted 00:19 Nov 29, 2018 |

It depends on which Pane you are using but if you can add a pane that replaces the old one then you can remove the last pane you added by getChildren() or just using the inherited method .remove(). A pane is just an object. If you can access it you can remove it and you save yourself the hassle of having to run code over and over again. So instead of running your program again, the button can just remove the last pane added. It depends which type of pane you used but the process is the same as if you were removing the last element of an arraylist manually.

bsanc115
Posts: 7
Posted 00:33 Nov 29, 2018 |

I think he means allowing for a button to fire a “new menu” as well as being able to return to the original “menu” from the new menu.  Attaching  the new pane to a new scene would be the most efficient way to do this because you’d be able to navigate  through  the first menu and second menu just by clicking the respective buttons in each pane.  Removing a pane completely  wouldn’t allow you to do this 

rgallegos
Posts: 29
Posted 01:19 Nov 29, 2018 |

Like I said, it depends on the type of pane used. Since the new pane is completely replacing the old one, it sounds like he's using a StackPane. That means that all the resources and memory allocated for the old one still exist. If you remove the last pane added to the stack, then you will go back to the previous one. Yes, you can continue stacking more panes to make it seem like you are returning to the main menu, but each instance requires more memory and you'd risk a runtime error when you run out of memory.

mferras2
Posts: 7
Posted 01:32 Nov 29, 2018 |

Yeah I meant more so just having a new pane pop up and have just a search function for example.

bsanc115
Posts: 7
Posted 01:46 Nov 29, 2018 |

Yeah that's what I have.  You wouldn't continue stacking panes every time you fire the event though.  A basic example is you create a single instance of the first pane and a single instance of the second pane , you attach those panes to their two respective scenes.  The two panes contain the respective node, in this case a button, that fires the .setScene() event.  You're essentially just firing the events back and forth in order to navigate between the two "menus".  I don't see why there would be a memory allocation issue unless I'm missing something

mferras2
Posts: 7
Posted 01:55 Nov 29, 2018 |

I'm assuming also when the event handler fires on the second button (secondary scene) that you combined the task of going back to the menu and also whatever back end code needed, like a save button that adds a person?

bsanc115
Posts: 7
Posted 02:03 Nov 29, 2018 |

I have multiple buttons on the second scene but only one of them returns to the original menu.  The other buttons call methods from the backend code like adding an Employee, Student, etc. 

rgallegos
Posts: 29
Posted 02:04 Nov 29, 2018 |

"Yeah I meant more so just having a new pane pop up and have just a search function for example."
Like a separate window? It's possible to have multiple stages if you don't want to run the program from one window.

"I don't see why there would be a memory allocation issue unless I'm missing something"
I thought your comment "a new pane to a new scene" was creating a new instance every time the button was pressed but now I see what you mean. That does sound like a good idea.

bsanc115
Posts: 7
Posted 02:12 Nov 29, 2018 |

Yeah,by newScene in the event handler example I meant set to the second scene and not a new one every time. Sorry, should’ve used a different variable name lol