In short, you can't. Not by setting an option anyway. There's a
longstanding bug on Suns database. Included in the comments on the bug
there are a couple of suggestions for changing the behaviour of JTable
to get this to work.
See: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4521075
Essentially, you have derive from the current table UI, uninstall
their drag gesture listener (a mouse listener which refuses to start a
drag on an unselected row) and install one of your own which *will*
start a drag under those circumstances. Just take a copy of the UI
code for the JTable drag recognizer, modify it and install it instead.
If you do this, then selection won't move because the recognizer
consumes the mouse event, and it never gets to the selection code. See
the comment by 'scmorr', in his? case, he? wanted the dragged row to
be selected, so reordering the listeners was enough. In my case I
*didn't* want to select the dragged row, so I had to do more work.
Unfortunately, the code's not mine (though I wrote it) so I can't post
it...
HTH
Steve
> In short, you can't. Not by setting an option anyway. There's a
> longstanding bug on Suns database. Included in the comments on the bug
> there are a couple of suggestions for changing the behaviour of JTable
> to get this to work.
>
> See: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4521075
Thanks for the link. It sure is entertaining reading. I agree that Sun is
most negligent in their approach to outstanding defects. You'd think that
with the attention this bug report has generated, it would be high on the
priority list. At least they could publish a work-around until the "real"
fix comes through the pipeline.
> Essentially, you have derive from the current table UI, uninstall
> their drag gesture listener (a mouse listener which refuses to start a
> drag on an unselected row) and install one of your own which *will*
> start a drag under those circumstances. Just take a copy of the UI
> code for the JTable drag recognizer, modify it and install it instead.
What?? You mean I have to find some OPP (other people's problem) code,
decipher it, learn about some archaic computer-science-class concepts, fix
the problem, integrate it into my real-world application, document it, trace
it, and later remove it when Sun finally gets around to fixing it?
> If you do this, then selection won't move because the recognizer
> consumes the mouse event, and it never gets to the selection code. See
[quoted text clipped - 4 lines]
> Unfortunately, the code's not mine (though I wrote it) so I can't post
> it...
Thanks, but can you be a bit more specific? You could, of course retype it
from memory without violating your employer's NDA. -- or better still, ask
them politely (via letter) for permisssion to publish that portion of code.
(yea, I know, lots of work, can of worms...)
thanx,
Dar7yl (the 7 is silent)
SPC - 29 Jun 2004 14:51 GMT
Ever heard the one about not looking a gift horse in the mouth? :-)
I'll see what I can do. I have to extract the code from some other
stuff I also put into the UI to make it work better with a specific
use of JTreeTable that my employer required. One side effect of my
changes is that dragging to select rows and columns no-longer works.
I'm sure you'll be able to unpick what you need from the code. But
it'll have to wait until I've got a bit more time. (days rather than
weeks or months!).
What's depressing it that they apparently have no plans to change the
thing so that it behaves the same as many other windows tables on
windows. It wouldn't be beyond the wit of man to put in some sort of
property that governed drag operations and let the person using the
table decide how it should behave. Ho hum.
Steve
> > In short, you can't. Not by setting an option anyway. There's a
> > longstanding bug on Suns database. Included in the comments on the bug
[quoted text clipped - 36 lines]
> thanx,
> Dar7yl (the 7 is silent)
dar7yl - 30 Jun 2004 05:44 GMT
thanx again,
Dar7yl (the 7 is silent)
> Ever heard the one about not looking a gift horse in the mouth? :-)