Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Linking two JPanels with a JButton

 
Sam Swash
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to know a hint or someone tell me the overall structure of implementing the feature that if a user clicks on a JButton they are redirected to another JPanel.

Thanks,
 
Campbell Ritchie
Sheriff
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Depends what you mean by "new panel". If you wish to bring a new panel to the top, there are certain kinds of layout which are good for that: this one, for example.

I shall move this thread because we usually discuss GUI-related questions elsewhere.
 
Sam Swash
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I mean is that within the same FrameView there are two JPanels, and a button on one JPanel is, on click, redirects the user to the other panel.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are methods which request focus, and you can put the panels into an array and iterate the array, requesting focus on different members of the array in turn. That's one way to do it, and there are doubtless many others . . .

But I am a bit confused by the notion of redirecting "to a panel" when both panels are visible to the user anyway. Why don't you simply click a panel?
 
Sam Swash
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first panel has a button "Register" and the second panel is the register form, so when the user clicks on "register" button they are directed to the "register" panel, which is the other panel
 
Sam Swash
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What i'm asking is similar to use of tabs where a button click on one tab can redirect the user to another tab, but i would like to understand about how a button click on one panel can redirect the user to another panel.
 
Rob Spoor
Sheriff
Pie
Posts: 20606
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you checked the link in Campbell's first post?
 
Sam Swash
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes i have...and what i'm asking is similiar to use of tabs where in this case someone clicks a button on one panel and they are taken to another panel within the same jFrame.
 
Rob Spoor
Sheriff
Pie
Posts: 20606
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And that's just what CardLayout can do for you. But I must admit, I expected a link to the Java tutorial in the Javadoc page of CardLayout. So try http://download.oracle.com/javase/tutorial/uiswing/layout/card.html instead.
 
Sam Swash
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the link,

A great Help!
 
Rob Spoor
Sheriff
Pie
Posts: 20606
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
Campbell Ritchie
Sheriff
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote: . . . I expected a link to the Java tutorial in the Javadoc page of CardLayout. . . .
So would I. Most Components etc have a "How to use XXX" link in their documentation. I didn't look for it earlier, however.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic