Michael Dunn wrote:sorry, but I'll read it here, not at youtube.
i.e. post the code here
I've got something additionally to that
Somethimes the table requires a double click to select it
Sometimes the mouse event just got eaten
Thanks
Jack
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
1
before you go any further, dump mouseClicked() - it doesn't always fire.
run this demo, click anywhere on the panel, and you should see this printed out
pressed
released
clicked
note the order
now press and hold the left mouse button (anywhere), drag the mouse a few pixels left right up or down,
now release the left mouse button, and you'll notice mouseClicked() will not fire.
Jacky Luk
Ranch Hand
Joined: Aug 02, 2012
Posts: 201
posted
0
Michael Dunn wrote:before you go any further, dump mouseClicked() - it doesn't always fire.
Yes, like what you said, mouseClicked didn't fire, what do I do? Do I enter all the logics into the mousePressed Event handler?
Thanks
Jack
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
> Do I enter all the logics into the mousePressed Event handler?
most times mousePressed() is the best choice, however, there are times
when mouseReleased() will be better - just a matter of testing.
Jacky Luk
Ranch Hand
Joined: Aug 02, 2012
Posts: 201
posted
0
Michael Dunn wrote:> Do I enter all the logics into the mousePressed Event handler?
most times mousePressed() is the best choice, however, there are times
when mouseReleased() will be better - just a matter of testing.
Micheal is correct in saying the mouseClicked event doesn't always fire but there good reasons for that, ie a mouse click is generally considered to have occurred when the user has pressed and released the mouse button (or pressed and released a touch screen etc) within 'n' pixels of each other within the same component.
Be careful before ditching mouseClicked, there are potential problems with just using mousePressed or mouseReleased. For example if using just mousePressed you can't drag the mouse over several cells of a JTable to highlight multiple cells, users can be surprised when something happens before they have released the mouse button etc. If using just mouseReleased does the user really want the program respond to the event if say they have pressed the mouse button on another component, decided they didn't want to click there so moved the mouse over the JTable and released the button.
From glancing through the 135 lines of code, it rather looks like you want to respond to a selection change. If that's so, a MouseListener is not the appropriate listener; use a ListSelectionListener instead.
luck, db
There are no new questions, but there may be new answers.
Tony Docherty wrote:If using just mouseReleased does the user really want the program respond to the event if say they have pressed the mouse button on another component, decided they didn't want to click there so moved the mouse over the JTable and released the button.
That doesn't trigger a MouseListener added to the table. mouseReleased events are generated for the component over which the mouse was pressed.
Tony Docherty
Bartender
Joined: Aug 07, 2007
Posts: 1225
3
posted
0
Darryl Burke wrote:
Tony Docherty wrote:If using just mouseReleased does the user really want the program respond to the event if say they have pressed the mouse button on another component, decided they didn't want to click there so moved the mouse over the JTable and released the button.
That doesn't trigger a MouseListener added to the table. mouseReleased events are generated for the component over which the mouse was pressed.
Good point. Yes that part of my statement was wrong.
Although the essence of what I was saying still applies, in that by checking for mouseReleased rather than mouseClicked if the mouse is dragged away from the component an event will be handled that the user possibly wouldn't expect.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.