• Post Reply Bookmark Topic Watch Topic
  • New Topic

Drag and drop & JTable related Problem

 
Vishal Methi
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Friends,
I want to drag the content of the particular cell in the JTable , so could any plz help me how to solve this problem...... this is my deadline period so it'll be more helpful for me if u post me the reply asap........
Thanx ,
Vishal
 
clio katz
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JTable implements COPY drag-n-drop (DND) data transfer support *at the component level* (1.4) ... so if you want to DND a *cell* within the JTable, you have to get creative...
First place to reference might be the sun tutorial (http://java.sun.com/docs/books/tutorial/uiswing/misc/dnd.html#transferableClasses)
If you look at the 'data transfer support' chart, you'll probably realize that you'll have to break-out some custom code to get the job done. (For example JTable will treat 'text' cells as JLabels by default, ... and you won't find JLabel on the chart..)
At the minimum, you'll need to write a custom transfer handler. In a broader case, I imagine you could write custom DND component(s) to represent the cell(s) in your table, and/or your table.
[Incidentally, I tried to solve this problem not too long ago, and I backed out because (1) I'm not crazy about the Java DND support (I find it it a little unresponsive i.e. difficult to trigger drag-selection with the mouse in a table/list), and (2) Cell selection in the JTable is not always first-click ...
Instead, I attached a mouselistener to the JTable, and I use the left-double-click to 'export' value of current cell, and right-double-click to import it to selected cell. Tho this is pretty much equivalent to a cell-level copy-n-paste accelerator key sequence, but a few less clix:-)

hth
 
Vishal Methi
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear clio katz
Thanx for ur co-operation... Now i m able to drag the content of the cell but i didnt what to write in
DragGestureRecognized(DragGestureEvent) {}.......
and how to get this content in drop( DropTargetDropEvent ) ......
i m using StringTransferable is it correct and according to u what i have to use for transferable and dataFlavor ......
Thanx
Vishal
 
clio katz
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for a late response - I've been offline recently!

I believe you're asking is whether you are required to write both the export-side (something you may have already enabled by setting cells drag-enabled and using single-interval-selection) AND the import side (a full-blown transfer handler and implementation of 'transferable').

my short answer would be 'yes' :-> (need to write code for both sides of transfer)

for both of our sakes, i won't give a long answer because i have only implemented or toyed around with this on less-complex components than jtable.

HOWEVER, i would urge you to have a look at sun's example for an arraylist. it should have (nearly) all you need. above that, you will just need to wrest enough control from the jtable to be able to manage the UI (mouse,keybd) actions and validate+persist the cell content.

you can find the arraylist example at:

http://java.sun.com/docs/books/tutorial/uiswing/misc/example-1dot4/

best of luck to you - you're halfway there! (or perhaps 100% there by now)

hth
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!