java - How to make JTable click on unselected do a drag instead of a select -


if have jtable set table.setselectionmode(listselectionmodel.multiple_interval_selection) , click drag on row not selected, starts selecting multiple rows. don't want behavior. want if click on node, if it's not selected, start dragging it.

we need multi select mode on, setting single select (which result in behavior want) not option.

update: @ point, appears require type of ugly hack since logic in private method basictableui$handler.canstartdrag

i found 1 possible solution. bracket mouse listeners can lie call iscellselected during canstartdrag call.

subclass jtable (or in case, jxtreetable). in constructor call this:

private void setupselectiondraghack() {     // bracket other mouse listeners may inject our lie     final mouselistener[] ls = getmouselisteners();     (final mouselistener l : ls)     {         removemouselistener(l);     }     addmouselistener(new mouseadapter()     {         @override         public void mousepressed(final mouseevent e)         {             // note: might not necessary check row, but... figure it's safer maybe?             mousingrow = rowatpoint(e.getpoint());             mousinginprogress = true;         }     });     (final mouselistener l : ls)     {         addmouselistener(l);     }     addmouselistener(new mouseadapter()     {         @override         public void mousepressed(final mouseevent e)         {             mousinginprogress = false;         }     }); } 

and you'll need this:

@override public boolean iscellselected(final int row, final int column) {     if (mousinginprogress && row == mousingrow)     {         // lie canstartdrag caller. tell truth else.         final stacktraceelement[] elms = thread.currentthread().getstacktrace();         (int = 0; < 3; i++)         {             if (elms[i].getmethodname().equals("canstartdrag"))             {                 return mousinginprogress;             }         }     }     return super.iscellselected(row, column); } 

it's ugly hack in many ways, but... seems work.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -