Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

linking two jpanels  RSS feed

 
abhishek rathur
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am working a desktop application,in which i am having a jpanel which is a login page,what i want is to move to other jpanel on successful login .
 
Mohamed Sanaulla
Bartender
Posts: 3174
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One possible approach would be-
Add the panels to the JFrame- Set the ones not required to Visibility =false
Based on which panel to Hide/Show you can alter the Visibility value accordingly.

For this there's a method- setVisible(boolean). Also check out the Swing tutorial if you want to learn how to use the components.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think playing around with the visibility is a good idea.

Check out CardLayout It helps you switch contents.
In case you want to switch from panel1 to panel2 without using card layout you can call the remove() and add() on the container. Just don't forget to invoke() as well as repaint() to refresh the UI after the remove/add
 
Rob Spoor
Sheriff
Posts: 21047
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:I don't think playing around with the visibility is a good idea.

Check out CardLayout It helps you switch contents.

Actually, CardLayout uses switching invisibility in the background. But I agree that letting it do the hard work is a better idea.

Just don't forget to invoke()

I think you meant invoke revalidate(), right?
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:
Just don't forget to invoke()

I think you meant invoke revalidate(), right?


Darn. Yes. I meant invoke revalidate() as well as repaint().
Thanks for the catch Rob!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!