• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Drag and drop & JTable related Problem

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic