Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

CardLayout switching panels problem  RSS feed

 
tajinder pal singh
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

i am trying to switch panel on click of a button but nothing is happening.





I read the oracle doc example, i understand the concept but still nothing is happening on show,first ,next method of CardLayout in ActionPerformed. Code is highlighted where i am facing problem.
Any advice would be much appreciated. Thanks.
 
Rob Camick
Ranch Hand
Posts: 2800
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) A class name should start with an upper case character. "text" is not a proper name. Don't be lazy even if this is a test class.

2) cl1.show(mainPanel, (String)e.getActionCommand()); - does nothing. The action command will be the text from the button, which doesn't match the constraint you provided when you add the panel to the card layout so get rid of this code

3) cl1.first(mainPanel); - the panel containing the "second button" is the first panel, so there is no need to swap panels. Try the "last" or "next" method.
 
Paul Clapham
Sheriff
Posts: 22474
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your ActionListeners both display the first panel in the CardLayout. You mentioned the "next" method but you don't call it anywhere. Perhaps you just forgot to do that? If you insert a call to "next" between lines 66 and 67 of your posted code, it does what you want.
 
tajinder pal singh
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul And Rob . It Works.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!