Friday 10 August 2018

java - What is the proper way to navigate between windows?




I am trying to make a simple Customer tracking program.It stars with a window with 4 buttons and you choose a task to do.




I need to navigate between different windows
-Home Menu
-New Customer
-Customer
-Reports



What i do is creating different Jframes for each task but i don't know if it is the right way to do.



So my question is What is the proper way to navigate between windows on Java?



Answer



Please do not create multiple JFrames unless absolutely necessary.



Why?




  • There's multiple icons in the taskbar (on Windows and Linux).

  • Switching windows is an added burden to the user.

  • It raises issues with, e.g., the close button (do they all close if any close? is there one master?), etc.




Instead:



Consider using a JTabbedPane.




To create a tabbed pane, instantiate JTabbedPane, create the components you wish it to display, and then add the components to the tabbed pane using the addTab method.




For example:




JTabbedPane tabbedPane = new JTabbedPane();

JComponent someComponent = ...
tabbedPane.addTab("Tab 1", someComponent);

JComponent anotherComponent = ...
tabbedPane.addTab("Tab 2", anotherComponent);






Alternatively, you could use a CardLayout if you only want your users to see one view at a time.




The CardLayout class manages two or more components (usually JPanel instances) that share the same display space. Conceptually, each component that a CardLayout manages is like a playing card or trading card in a stack, where only the top card is visible at any time.



No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...