aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Row Selection isn't that slick? Why? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Row Selection isn Watch "Row Selection isn New topic
Author

Row Selection isn't that slick? Why?

Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 601
When I click on a row, it doesn't respond, I have to click it twice to activate that row. Why? how come row selection is that slow reflex?

Is that the jTable can't distinguish between row and cell selections?

Thanks
Jack
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
that snippet works OK for me - clicking a cell highlights the row, and puts focus border around cell.

unless you're talking about edit mode - that requires the extra click.
Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 601
Michael Dunn wrote:that snippet works OK for me - clicking a cell highlights the row, and puts focus border around cell.

unless you're talking about edit mode - that requires the extra click.


http://youtu.be/zrhJWoKtOs4

The mouse clicks don't work well....
Thanks
Jack

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
sorry, but I'll read it here, not at youtube.

i.e. post the code here
Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 601
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
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: 601
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
> 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: 601
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.


Thanks Mike, I am done with it.
Jack
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2420
    
  50
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.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4664
    
    5

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.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4664
    
    5

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: 2420
    
  50
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://aspose.com/file-tools
 
subject: Row Selection isn't that slick? Why?