• Post Reply Bookmark Topic Watch Topic
  • New Topic

CardLayout and InputVerifier

 
Ken Clark
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a typical GUI, the input verifier is executed prior to focus being
lost, and going somewhere else. That does not seem to be the case in
the CardLayout. I have an input verifier on a text field, and a
button that moves us to the next page in the layout. If the button is
pushed ( thus attempting to move focus ), the verifier is called, and
a message of failure is produced, but I've also now moved to my next
page.

Is there a trick to using this in the CardLayout?

k
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your event code that changes cards check with your verifier(s) that their JComponents are all verified before allowing the cards to change. Here's a demo with code adapted from the InputVerifier api.
 
Ken Clark
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I saw the shouldYieldFocus method in the API, but the docs say that it will first call the .verify method. My .verify method calls an error dialog, so won't the error dialog be displayed twice?
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could move the dialog to your button ActionListener or you could set a boolean in your verify method that is available to your button ActionListener
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!