Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Removal of swing event  RSS feed

 
christophe seguinot
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I would like to intercept action on my save button. When the user click on save, I have a validor which is ran. In this validator I would like to cancel the "save" action in some cases. So I thought maybe it is possible to remove the save event from the event queue.

Do you know if it's possible ?

Cheers,

Chris
 
Stephan van Hulst
Saloon Keeper
Posts: 7003
110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not just put an if condition in your button's event listener that only executes the save if all the conditions are met, and displays an error message otherwise?

Alternatively, you can just disable the save button when the conditions aren't right. In this case you will have to have event listeners in other components that determine the conditions, and disable or enable the save button depending on their state.

We can probably give you more advice if you provide us with a more detailed picture of when you don't want the user to be able to save something.
 
Aromal ayyappan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

We can add a KeyListner to the Save Button, And inside the keyPressed () method , do the validation part.
If the validation is unsuccessful , we can use a keyevent.consume() .
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aromal ayyappan wrote:Hi,

We can add a KeyListner to the Save Button,

Please don't. That's an even worse perjury than the occasional noob error of adding a MouseListener to a JButton.
 
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 would prefer method chaining.
Save-Validate-If validated, proceed, else warn the user.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!