GeeCON Prague 2014*
The moose likes Swing / AWT / SWT and the fly likes ListSelectionListener    getValueIsAdjusting() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "ListSelectionListener    getValueIsAdjusting()" Watch "ListSelectionListener    getValueIsAdjusting()" New topic
Author

ListSelectionListener getValueIsAdjusting()

Younes Essouabni
Ranch Hand

Joined: Jan 13, 2002
Posts: 479
Hello all,
I have a JTable on which I added my own ListSelectionListener. I don't want to do any useless process while the user is choosing his row. I can get this behaviour with this method in my ListSelectionListener.

It is working perfectly fine if the user is selecting a row with the mouse. But if the user is selecting a row with the keyboard (which will probably be the default behaviour) the method getValueIsAdjusting never return true, and all the code not supposed to be processed, get processed many times. It leads to a drastic increasing of memory and a big slow down. How can I avoid this?
Thx in advance.
P.S: You may experiment it with this ListSelectionDemo. It has the same problem
[ January 23, 2003: Message edited by: Younes Essouabni ]

Younes
By constantly trying one ends up succeeding. Thus: the more one fails the more one has a chance to succeed.
Younes Essouabni
Ranch Hand

Joined: Jan 13, 2002
Posts: 479
Moving this up, as I didn't found any answers.
Any help is welcome
Thx in advance
Younes
Younes Essouabni
Ranch Hand

Joined: Jan 13, 2002
Posts: 479
Maybe somebody could help me
Any guess is welcome
Eric Blische
Greenhorn

Joined: Feb 02, 2003
Posts: 16
Just a Guess but you might
try overriding getValueIsAdjusting()
in your ListSelectionListener object
to return a value more in league with
what you want to know ?
Eric
Eric Blische
Greenhorn

Joined: Feb 02, 2003
Posts: 16
Thinking about it for a minute it occurs to me the behavior SOUNDS to me to be right, the getValueIsAdjusting() should return true only if the event is indicative of a "temporary" list change, ie, if the focus passes to a popup menu and the like. So when you select a row with the keyboard, it is a "permanent" selection ... getValueIsAdjusting() should always return false (and you state it does). Maybe you problem can be solved by minimizing the work done when a row is selected, perhaps by caching, or another strategy to limit the overhead ?
Eric
Younes Essouabni
Ranch Hand

Joined: Jan 13, 2002
Posts: 479
Thx Eric for your answer. I just saw it, sorry
There is still something that I don't get.
...the getValueIsAdjusting() should return true only if the event is indicative of a "temporary" list change, ie, if the focus passes to a popup menu and the like...
Why would the focus be different if I select with my mouse or the keyboard? If you select a row with the mouse, the getValueIsAdjusting() return true until you release the mouse button. Why I don't have such a behaviour with my keyboard?
So maybe that the masters from Manning can help me. It's a long time that I'm praying for you to come preach in here
Matt Robinson
author
Greenhorn

Joined: Apr 30, 2001
Posts: 16
This seems to be a bug. Whenever you are holding down CTRL or SHIFT (or their equivalents on other platforms), this method should return true because your selection is still in progress. I would work around this by overriding that method and returning true if either CTRL or SHIFT is currently down.


Matthew Robinson
co-author of Swing Second Edition (2003, Manning Publications).
Younes Essouabni
Ranch Hand

Joined: Jan 13, 2002
Posts: 479
Thx Matt. In fact I never knew that I have to hold on CTRL or SHIFT. I tried it but nothing change. So, I will override the method and do nothing while the down array is pressed.
Thx a lot
Younes Essouabni
Ranch Hand

Joined: Jan 13, 2002
Posts: 479
Just for the case that anybody would need it later. I created a class that implements ListSelectionListener and KeyListener

It is working great for me, avoiding memory consumption. Thanx for all the help.
 
GeeCON Prague 2014
 
subject: ListSelectionListener getValueIsAdjusting()