Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JButton - Click & Drag prevents Event  RSS feed

 
Hesham Gneady
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ,

I created my Swing program and while testing it i noticed that sometimes when i click on a JButton, the "MouseClicked" event does not fire.

After some tries i noticed the reason, it's because sometimes i click on the JButton + make a tiny drag with the mouse on it before ending the click.
I know ... it's a trivial thing, but not for the users using the application.

I didn't want to use "MousePressed" event(which doesn't do this behavior) so i created a code to prevent this behavior :

This will fix the problem, but now i've to apply this code to all my program Buttons/Radio buttons/.... Sure there's another way ??
I'm saying this because i noticed that Swing MessageDialogs don't do this behavior + they're not using the "MousePressed" event !!

Thanks

 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> I know ... it's a trivial thing, but not for the users using the application.

and rightly so - using mouseClicked is generally a poor choice.

> ...i noticed that sometimes when i click on a JButton,

ActionListener is the better choice for a JButton:
1) it is generally the standard listener or a JButton
2) setting the button disabled, disables an actionListener,
not so a mouseListener (unless this is the effect you're after)
 
Hesham Gneady
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ActionListener is the better choice for a JButton

Well, it's my first time to know this ... But i can't re-code my application again
That's why i'm looking for easy solutions now.
 
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
Hesham Gneady wrote:
ActionListener is the better choice for a JButton

That's why i'm looking for easy solutions now.


The easy solution is using an actionListener instead of a mouse listener.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hesham Gneady wrote: ... But i can't re-code my application again

You'd better get out of this mind-set fast if you're going to continue coding. Much of programming (most?) involves re-coding things. Might as well start now.
 
Hesham Gneady
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok ... I'll starting implementing it.
Thanks everyone.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!