• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Row Selection isn't that slick? Why?

 
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 634
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 4632
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry, but I'll read it here, not at youtube.

i.e. post the code here
 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 4632
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 634
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> 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
Posts: 634
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic