0

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?

1 Answers1

2

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.

wchargin
  • 15,589
  • 12
  • 71
  • 110
  • Jtabbed does not seem to be right choice.Actually what i want is something like in android UI.You start the app,tab on something a new interface appears. – user1906555 Jun 08 '13 at 22:56
  • +1 for `JFrame` pointers and yeah `CardLayout` is a better option – exexzian Jun 08 '13 at 23:07