-3

I got my program, that can connect to a Database working! ( Hooray ) But now, I ran into a new problem. I read that using multiple JFrame windows (and closing the old one) is not user friendly, and a bad learning habit.

So now I am wondering, is there a way to switch between Panels, or something similar?

Example:

JFrame with Login & Password. -- Users logs in, goes to the next 'screen' where he or she can see the Database info, cause he or she logged in! What should I use, any good methods out there?

Community
  • 1
  • 1
Wesley
  • 57
  • 1
  • 7

4 Answers4

1

you may want to check CardLayout

Roberto Attias
  • 1,883
  • 1
  • 11
  • 21
  • I have, but ( correct me if i'm wrong ) isn't it like working with Tabs ? Like in an Internet browser? And if so, is it possible to force close certain tabs? Cause i don't want the 'login' tab to be open, after it's used. – Wesley Jan 04 '17 at 02:51
  • *"I have, but ( correct me if i'm wrong ) isn't it like working with Tabs ?"* A `JTappedPane` provides the tabs you refer to, a card layout doesn't. – Andrew Thompson Jan 04 '17 at 09:39
-1

The simple answer is yes you can. The idea is to have a localized class that contains a method that outside classes can call passing a jPanel then simply add that panel to your jFrames content pane (which in turn will remove the other panel). There are many ways to go about this and I hope you find one that works and I hope this answer helps you as well.

paul
  • 96
  • 9
-1

Here is the procedure I generally follow. I create and open a new Frame and make the parent frame invisible. Again when child frame is closed I make the parent frame visible. I am using this procedure for a long time and not facing any problem.

This is the piece of the code executed when login button is clicked.

... setVisible(false); //Hide the login page DBPage page=new DBPage(this, value1); // DBPage is another JFrame page.setVisible(true);

I feel this much of code is enough to understand.

Prabir Ghosh
  • 430
  • 3
  • 7
  • I do understand! But does this give the 'flash' effect? Cause between the transistion of the two JFrames, there is 'white space' if i'm right. – Wesley Jan 04 '17 at 02:53
  • No 'white space' is visible. You can try this. This is OK for login page to main page. However, in main page try to maintain the navigation using tabs and CardLayout. When you close the main page bring back the login page clearing the user's session data. – Prabir Ghosh Jan 04 '17 at 03:02
  • Alright thanks alot! I'll try it now, and for tabs I will definitely use CardLayout, as everyone has been mentioning it. I can't upvote your comment, but thanks for your help! – Wesley Jan 04 '17 at 03:04
  • You can also use JTabbedPane, that is easy to use. – Prabir Ghosh Jan 04 '17 at 03:07
-1

JLayeredPane might work.

http://docs.oracle.com/javase/8/docs/api/javax/swing/JLayeredPane.html

You could have several layers on top of each other, the login screen, etc. and show the layer that is most relevant at the time.

A previous question may prove useful:

Java Swing - how to show a panel on top of another panel?

Community
  • 1
  • 1