Results 1 to 2 of 2
Thread: Dran and Drop
- 08-29-2009, 09:26 PM #1
Senior Member
- Join Date
- Nov 2007
- Posts
- 160
- Rep Power
- 6
Drag and Drop
I have two JLists. I want to be able to drag a selection from one into the other and then do stuff with the indices that have been dragged over. For example, I drag the value at index 1 from myFirstJList to mySecondJList and then, for simplicities sake, print out "1"...
This is what I tried based on some example from the Java tutorials:
With this I can drag a cell or cells from the JList into a JTextArea or something and it will paste the cell indices. It doesn't work if I try to drag into another JList - it shows the "drag not supported" sign thingy... I didn't include the importData method because it didn't seem to be firing anyway... I know that I include include the code I want in the createTransferable method above, but it fires as soon as you start dragging, and I only want it to happen after the drop obviously.Java Code:myFirstJList.setDragEnabled(true); myFirstJList.setTransferHandler(new TransferHandler() { protected Transferable createTransferable(JComponent c) { int[] indices = ((JList) c).getSelectedIndices(); String text = ""; for (int i = 0; i < indices.length; i++) { text += indices[i]; } return new StringSelection(text); } public int getSourceActions(JComponent c) { return COPY_OR_MOVE; } });
NOTE 2: I cut down the code to make it as simple a possible, so I could see exactly what was happening.
To sum up:
1) Why will it work with a JTextArea but not a JList?
2) How I can I choose what happens at the drop? As I said, the importData method doesn't seem to fire at all...Last edited by carderne; 08-30-2009 at 08:27 AM.
- 08-30-2009, 08:29 AM #2
Senior Member
- Join Date
- Nov 2007
- Posts
- 160
- Rep Power
- 6
Similar Threads
-
drop down value not setting in IE7
By radhikavk in forum New To JavaReplies: 0Last Post: 04-18-2009, 07:59 AM -
dynamically changing drop down box on selection in first drop down
By anjali in forum Advanced JavaReplies: 1Last Post: 04-01-2009, 10:28 AM -
drop down menu
By mike eriksen in forum AWT / SwingReplies: 2Last Post: 06-19-2008, 07:33 AM -
How to use a drop-down box in Struts
By piterskiy74 in forum Web FrameworksReplies: 1Last Post: 02-13-2008, 11:42 AM -
Drop down menu
By BenNeiderlander in forum New To JavaReplies: 3Last Post: 02-05-2008, 07:35 AM


LinkBack URL
About LinkBacks

Bookmarks