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 ]
By constantly trying one ends up succeeding. Thus: the more one fails the more one has a chance to succeed.
Joined: Jan 13, 2002
Moving this up, as I didn't found any answers. Any help is welcome Thx in advance Younes
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
Joined: Feb 02, 2003
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
Joined: Jan 13, 2002
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
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.