Drag and Drop and Reordering Items in Lists
Just want to share this. In case, someone needs this.
http://jsbin.com/yavag/3/edit
-D
Hi,
not sure its the reason but you have huge bummer in your configuration.
<af:table value="#{pageFlowScope.prodReportBackingBean.prodReportTableData}"
var="row" styleClass="AFStretchWidth" rowBandingInterval="0"
rows="40" emptyText="No data to display." id="t1"
partialTriggers=":::cb1" columnStretching="column:c3"
*binding="#{pageFlowScope.prodReportBackingBean.prodReportTableBinding}"* summary="PROD TABLE">
JSF component bindings should not be to beans in a scope larger than request to avoid stale component instances.
Frank
Similar Messages
-
Drag n Drop files in Outlook Sharepoint Lists
Hi,
Can you let me know how to enable drag and drop of files in Sharepoint List in Outlook 2007. I have installed MOSS 2007. Currently its in read only mode.
ThanksCheck out EverSuite 'plugin for Outlook' from Ever-Team- We have an Outlook integration that supports
this type of functionality.
Eric
COLAVITA
EVER-TEAM
Tel. +33 (0)4 26
68 33 00
mail [email protected]
http://www.ever-team.com -
Custom Drag and Drop Component: When i add a skin, drag and drop no longer works?
I have a skinnableContainer that acts as a container for other drag and droppable items. This container's drop functionality is added from it's parent at the same moment the container is added.
This all works fine until i add a skin class to the skinnableContainer, now none of the draggable items can drop into the container as it did before.
I assume that the Group component wrapping the content from within the skin is acting as a block somehow, but i'm not sure how to allow the drop functionality through it?
Any ideas? Thanks in advance.Hello,
Thanks for your replies... I tried modifying the if clause,
but it did not work. I can use a trace statement to find out what
the target is and what level it is at, but I cannot do this when it
is in our presenter window.
The code that is causing the problem can be accessed right in
Flash. Just create a new quiz, then in the library, go to Quiz
Files --> Learning Interactions --> Assets --> Controls
--> Components, right click on drag and drop and select edit and
then go to the actions frame. I am sure you already know this, but
I just want to be clear I did not make this from scratch.
This code works great when the quiz is the root movie. But if
the quiz is encapsulated within another movie, it does not work. I
can drag the objects, but they just snap back to where their
starting points are. In the code I attached earlier...
"this._parent.Target1" used to be "target".
Just so you can see it all, I have attached the problematic
function.
What happens is that if "this._parent.Target1" is set to
"target", the movie will function fine in Flash, but will not work
in our presentation window. I can drag the draggable objects, but
they always snap back to the location of where they came from.
What this means is that the if clauses are not being run, and
the function is always running the else clause, which puts all of
the objects back at their starting point.
In the code attached, I am using "this._parent.Target1".
Again, works fine in Flash, but when I put it in the presentation
window, this time, I can drag the objects anywhere on the screen,
but when I drop them, they think that the dropZone is the question
itself, and not the Target (Target1). So I need to figure out how
to make Target1 be the dropZone in our presentation window.
Any ideas?
Thanks again for all your help! -
SWFLoader & Drag'n'Drop Problem
Hello folks,
So there is my problem ;
I made a flex swf, containing manual drag'n'drop of some
items from a box to an other box.
When I run this swf alone, the drag'n'drop works fine.
Then I created an other swf, which is my main application; it
initalizes a bunch of things, and each screens is a swf, like the
previous one with drag'n'drop.
When I get on the screen which loads the swf with
drag'n'drop, the startDrag run fine, I can catch an item and drag
it, but if I release the mouse button, the item stays stuck on the
mouse cursor. To get it move back to its box, I have to move the
cursor out of my browser window, or to right click so it looses
focus, or something like this.
Is this a flex bug? Do I have something special to do? Maybe
the main application events conflicts with the embedded swf events.
I really need help on this, I have already spent some time on it,
and I can't figure how to solve this.
Thanks.Using
stage.addEventListener(MouseEvent.MOUSE_UP, mouseUp), the
mouse up event is fired during drag ... 3 times. I don't know if
this is normal, but this seems weird to me, it should fire only one
time, I think.
Whatever, now that I have this mouse up event, how can I stop
the drag process? I found nothing useful in the DragManager
interface, but a stopDrag() function on the item I'm dragging
(which extends Box).
The following
doesn't work:
private function mouseUp(event:MouseEvent):void
if (DragManager.isDragging)
stopDrag();
Any idea how to stop the drag process, with what I get here?
Also, any idea why the mouse event is triggered 3 times?
Thanks. -
Copy item from List A to List B, generate 2 rows in List B
Hi,
I would like to copy and update items from List A to List B. However, I want the item to be duplicated in List B.
I will explain my scenario
- List A contains a People Picker column of multiple selection and a Title column
- When the form is submitted, a workflow should trigger to copy the item to List B. If the People Picker column contains 2 values inside it, for example, user1;user2. The copied item should be duplicated in rows according to the number of users.
Example
Columns Title, Users, ID
List A - TicketNo1, User1; User2, 1
List B - TicketNo1, User1 1
List B - TicketNo1, User2 1
Can this be done OOTB or must we use some event receiver..has anyone ever done such a thing before?Hi,
Below code help you to accomplish your task using event receiver
public
override void ItemAdded(SPItemEventProperties properties)
//base.ItemAdded(properties);
if (properties.ListTitle ==
"ListA")
SPUser user = null;
//get value of fields
string strTitle = Convert.ToString(properties.ListItem["Title"]);
SPFieldUser userField = (SPFieldUser)properties.ListItem.Fields.GetField("TaskAssignUser");
SPFieldUserValueCollection fieldcollectionValue = (SPFieldUserValueCollection)userField.GetFieldValue(Convert.ToString(properties.ListItem["TaskAssignUser"]));
foreach (SPFieldUserValue fieldValue
in fieldcollectionValue)
user = fieldValue.User;
//Create items in another list
SPList destinationList = properties.Web.Lists["ListB"];
SPListItem targetItem = destinationList.Items.Add();
targetItem["Title"] = strTitle;
targetItem["WorkAssigned"] = user;
targetItem.Update();
Thank You,
Somnath Matere -
How to drag and drop item from list to another item in list and change their positions
I have a list field with multiple items. I want to select one item from list and drag and drop to another item in the list
after drop item on another item the position of items should be change. (Example:- if I select 1st item from list and drag and drop this item to 4th item in list after drop that item position of both item should be changed 1st item on 4th position and 4th item on 1st position)
I don't know how to do this.Please help me to find the solution.Hello Zoltan,
I do not believe that kind of option is built into the listboxes, but I was able to have similiar functionalities using property nodes. I have included an example program that I put together.
The big difference is that instead of dragging, you double click on the item you want to transfer. To highlight items as you go down the list, all you need to do is set the value to that list number.
Hope this helps you out!
Attachments:
Temp.vi 33 KB -
Possible List Drag and Drop bug
Hi all,
I am using a spark.components.List that I wish the user to be able to reorder by dragging and dropping. Therefore I have dragEnabled,dropEnabled and dragMoveEnabled all set to true.
I have a custom item renderer that has two states ('default' and 'notDefault' for the sake of argument) that the list uses. The currentState of the item renderer is determined by the data it is given.
When items are moved around they do get reordered correctly, however if I have an item in the 'notDefault' state and drag it somewhere it ends up rendered in the 'default' state after dragging, even if the data it is displaying requires the 'notDefault' state. What is more frustrating is that the item renderer reports its currentState as 'notDefault' even though it is showing 'default'.
The difference between the two states is that there is a VGroup with controls in it excluded from the 'default' state, and therefore if these are displayed before dragging (ie we are in the 'notDefault' state) they are consequently not displayed after dragging.
Anybody have any ideas?Might be a bug. File a bug or post a simple test case.
Alex Harui
Flex SDK Developer
Adobe Systems Inc.
Blog: http://blogs.adobe.com/aharui -
Drag and Drop to Change Order in a List
Does anyone know of an example where there is the ability to drag and drop elements in a list and thus change their order? (I.E. drag item one below item two and then item one and two change locations)
Thanks!Check out http://java.sun.com/docs/books/tutorial/uiswing/misc/dnd.html
There's an example towards the end of the page for drag-and-drop between 2 JLists. Might be a good starting point. -
Reordering of rows - issue with drag and drop of editable columns in table
JDeveloper: 11.1.1.6.0
ADF Faces - Drag and Drop for reordering of rows within the same af:table
I have a requirement for reordering rows in a table using drag and drop. This table is loaded using a list and I am able to programmatically do the reordering of the rows based on the events of drag and drop by manipulating the list. Reordering of rows is working fine if all the columns are read only. For all the input text and input date columns the values are not getting reordered. Anyone has any idea on what the issue may be with reordering of the rows for editable columns/rows (af:inputText and af:inputDate) in af:table. Below is what Iam doing on drop event which is a collection drop target.
public DnDAction dropCollection(DropEvent dropEvent) {
try
Object dropSite = dropEvent.getDropSite();
Transferable transferable = dropEvent.getTransferable();
DataFlavor<RowKeySet> rowKeySetFlavor = DataFlavor.getDataFlavor(RowKeySet.class, "rowmove");
RowKeySet rowKeySet = transferable.getData(rowKeySetFlavor);
RichTable table = (RichTable) dropEvent.getDragComponent();
if (rowKeySet != null)
CollectionModel dragModel = transferable.getData(CollectionModel.class);
Object dragM = dragModel.getRowData(0);
Object currKey = rowKeySet.iterator().next();
dragModel.setRowKey(currKey);
table.setRowKey(currKey);
OrderData orderData = (OrderData)this.prodReportTableData.get(Integer.parseInt(currKey.toString()));
this.prodReportTableData.remove(Integer.parseInt(currKey.toString()));
this.prodReportTableData.add(Integer.parseInt(dropSite.toString()), orderData);
OrderData orderDataAdded = this.prodReportTableData.get(Integer.parseInt(dropSite.toString()));
JSFUtils.addPartialTarget(this.getProdReportTableBinding());
catch(Exception e)
e.printStackTrace();
return DnDAction.MOVE;
Code snippet from UI:
<af:table value="#{pageFlowScope.prodReportBackingBean.prodReportTableData}"
var="row" styleClass="AFStretchWidth" rowBandingInterval="0"
rows="40" emptyText="No data to display." id="t1"
partialTriggers=":::cb1" columnStretching="column:c3"
binding="#{pageFlowScope.prodReportBackingBean.prodReportTableBinding}" summary="PROD TABLE">
<af:dragSource actions="MOVE" defaultAction="MOVE"
discriminant="rowmove"
dragDropEndListener="#{pageFlowScope.prodReportBackingBean.afterDragAndDrop}"/>
<af:collectionDropTarget dropListener="#{pageFlowScope.prodReportBackingBean.dropCollection}"
actions="MOVE"
modelName="rowmove"/>Hi,
not sure its the reason but you have huge bummer in your configuration.
<af:table value="#{pageFlowScope.prodReportBackingBean.prodReportTableData}"
var="row" styleClass="AFStretchWidth" rowBandingInterval="0"
rows="40" emptyText="No data to display." id="t1"
partialTriggers=":::cb1" columnStretching="column:c3"
*binding="#{pageFlowScope.prodReportBackingBean.prodReportTableBinding}"* summary="PROD TABLE">
JSF component bindings should not be to beans in a scope larger than request to avoid stale component instances.
Frank -
Issue : drag and drop from list control to tree control
Hi,
I was trying a drag and drop from list control to tree control. I have used some sample data to populate list and tree controls .
It is working fine . except one problem ..
Prob : when i drag an item to tree control .. it gets added .. now tree contains (X+1) data in list .. say X is the inital number of nodes in a tree node.
now if i drag another item from list to last item in the tree node .. i.e at X+1 index. .. it throws null pointer exception.
I am considerably new in flex programming . looking for help from experts ..
Below is my code :
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="horizontal"
creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.controls.listClasses.IListItemRenderer;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.utils.ObjectUtil;
import mx.collections.ICollectionView;
import mx.core.UIComponent;
import mx.managers.DragManager;
import mx.events.DragEvent;
import mx.controls.Alert;
import mx.controls.Label;
import mx.events.CloseEvent;
private var homePath:String="/home/e311394/dndTest/";
private var destPath:String="/home/e311394/dndDest/";
private var eid:String="e311394";
private var actn:String;
[Bindable]
private var cm:ContextMenu;
private var cmi:ContextMenuItem;
[Bindable]
private var dp:ArrayCollection;
private function init():void
cmi=new ContextMenuItem("Remove");
cmi.enabled=true;
cmi.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, contextMenuItem_menuItemSelect);
cm=new ContextMenu();
cm.hideBuiltInItems();
cm.customItems=[cmi];
cm.addEventListener(ContextMenuEvent.MENU_SELECT, contextMenuItem_menuSelect);
list.contextMenu=cm;
private function contextMenuItem_menuSelect(evt:ContextMenuEvent):void
list.selectedIndex=lastRollOverIndex;
private function contextMenuItem_menuItemSelect(evt:ContextMenuEvent):void
var loclSelectedRow:Object=list.selectedItem;
var lostrSelectedMenuItem:String;
lostrSelectedMenuItem=evt.target.caption;
if (loclSelectedRow != null)
var obj:Object=new Object()
obj.label=loclSelectedRow.label as String;
//Alert.show(obj.label);
if (lostrSelectedMenuItem == "Remove")
if(loclSelectedRow!=null)
var pth:String=homePath.concat(loclSelectedRow.label);
//Alert.show(pth);
//FlexDnDRemoteService.process(eid,"delete",pth,"-");
var coll:ArrayCollection=list.dataProvider as ArrayCollection;
if (coll.contains(loclSelectedRow))
coll.removeItemAt(coll.getItemIndex(loclSelectedRow));
public function onTreeDragEnter(event:DragEvent):void
event.preventDefault();
DragManager.acceptDragDrop(event.target as UIComponent);
tree.showDropFeedback(event);
protected function onTreeDragOver(event:DragEvent):void
event.preventDefault();
event.currentTarget.hideDropFeedback(event);
try
var index:int=tree.calculateDropIndex(event);
catch (e:Error)
DragManager.showFeedback(DragManager.NONE);
return;
tree.selectedIndex=index;
var draggedOverItem:Object=tree.selectedItem;
public function onTreeDragExit(event:DragEvent):void
event.preventDefault();
tree.hideDropFeedback(event);
private function showAlert():void
Alert.yesLabel="Move";
Alert.noLabel="Copy";
Alert.buttonWidth=70;
Alert.show("Copy / Move ?", "Confirm", Alert.YES | Alert.NO | Alert.CANCEL, this, alertListener, null, Alert.OK);
private function alertListener(eventObj:CloseEvent):void
var result:Boolean=false;
if (eventObj.detail == Alert.CANCEL)
//Alert.show("CANCEL");
return;
if (eventObj.detail == Alert.YES)
//Alert.show("YES");
result=true;
else if (eventObj.detail == Alert.NO)
//Alert.show("NO");
result=false;
var index:int=tree.calculateDropIndex(treedropevt);
//Alert.show("Drop Pos" + index.toString());
/* var treeList:ArrayCollection=tree.dataProvider as ArrayCollection;
Alert.show(" index"+index+"Length "+treeList.length);
if(index > treeList.length)
Alert.show("Returning");
return;
var items:Array=new Array();
if (treedropevt.dragSource.hasFormat("items"))
items=items.concat(treedropevt.dragSource.dataForFormat("items") as Array);
var parentItem:Object;
parentItem=getObjectTarget();
/* if (tree.dataDescriptor.isBranch(tree.indexToItemRenderer(index).data))
parentItem=tree.indexToItemRenderer(index).data;
else
var dropParentPackage:Object = tree.mx_internal::_dropData.parent as Object;
Alert.show("HAck"+dropParentPackage.toString());
parentItem=tree.getParentItem(tree.indexToItemRenderer(index).data);
//Alert.show("Lenght "+ObjectUtil.getClassInfo(parentItem).properties.length);
//Alert.show("Lenght "+ObjectUtil.getClassInfo(parentItem).properties.length);
var position:int=0;
/* if(ObjectUtil.getClassInfo(parentItem).properties.length==0)
Alert.show("Returning");
return;
if (parentItem != null)
try
while (tree.indexToItemRenderer(index).data != parentItem)
//Alert.show(tree.indexToItemRenderer(index).data.toString());
if (index > 0)
index--;
//Alert.show("Insiade");
position++;
catch (e:Error)
Alert.show("Catch" + index.toString());
return;
for each (var item:Object in items)
var obj:Object=new Object()
obj.label=item.label as String;
if (parentItem != null)
//Alert.show("ADDED");
tree.dataDescriptor.addChildAt(parentItem, obj, position++);
else
//Alert.show("PARENT NULL");
tree.dataDescriptor.addChildAt(tree.selectedItem, obj, position++);
var spth:String=homePath.concat(item.label);
//Alert.show(spth);
var dpth:String=destPath.concat(item.label);
//Alert.show(dpth);
if (result == true)
removeItems();
//FlexDnDRemoteService.process(eid,"move",spth,dpth);
else
//FlexDnDRemoteService.process(eid,"copy",spth,dpth);
tree.validateNow();
public function getObjectTarget():Object
var dropData:Object=tree.mx_internal::_dropData as Object;
if (dropData.parent != null)
return dropData.parent;
else
// if there is not parent (root of the tree), I take the root directly
var renderer:IListItemRenderer=tree.indexToItemRenderer(0);
return renderer.data;
public function removeItems():void
//remove moved elements
var items:Array=treedropevt.dragSource.dataForFormat("items") as Array;
var coll:ArrayCollection=list.dataProvider as ArrayCollection;
for each (var item:Object in items)
if (coll.contains(item))
coll.removeItemAt(coll.getItemIndex(item));
private var treedropevt:DragEvent;
public function onTreeDragDrop(event:DragEvent):void
treedropevt=event;
showAlert();
event.preventDefault();
tree.hideDropFeedback(event);
public function resultHandler(event:ResultEvent):void
Alert.show("Success", "Status");
public function faultHandler(event:FaultEvent):void
Alert.show(event.fault.faultString, "Failure");
]]>
</mx:Script>
<mx:ArrayCollection id="listDP">
<mx:Object label="File1.dnd"/>
<mx:Object label="File2.dnd"/>
<mx:Object label="File3.dnd"/>
<mx:Object label="File4.dnd"/>
<mx:Object label="File5.dnd"/>
</mx:ArrayCollection>
<mx:Number id="lastRollOverIndex"/>
<!--
<mx:ArrayCollection id="treeDP">
<mx:Object label="/home">
<mx:children>
<mx:Object label="dummy1.ks"/>
<mx:Object label="dummy2.ks"/>
<mx:Object label="e493126">
<mx:children>
<mx:ArrayCollection>
<mx:Object label="/home/e493126/sample1.ks"/>
</mx:ArrayCollection>
</mx:children>
</mx:Object>
</mx:children>
</mx:Object>
</mx:ArrayCollection>
-->
<mx:ArrayCollection id="treeDP">
<mx:Object label="/dndDest">
<mx:children>
<mx:ArrayCollection>
<mx:Object label="sample1.ks"/>
<mx:Object label="sample2.ks"/>
<mx:Object label="sample3.ks"/>
<mx:Object label="sample4.ks"/>
<mx:Object label="sample5.ks"/>
<mx:Object label="sample6.ks"/>
</mx:ArrayCollection>
</mx:children>
</mx:Object>
</mx:ArrayCollection>
<mx:List id="list"
itemRollOver="lastRollOverIndex = event.rowIndex"
width="50%"
dragEnabled="true"
dataProvider="{listDP}"
labelField="label"
allowMultipleSelection="true"
dragMoveEnabled="false">
</mx:List>
<mx:Tree id="tree"
width="50%"
dragEnabled="true"
dataProvider="{treeDP}"
dragEnter="onTreeDragEnter(event)"
dragOver="onTreeDragOver(event)"
dragExit="onTreeDragExit(event)"
dragDrop="onTreeDragDrop(event)"
labelField="label"
liveScrolling="true">
</mx:Tree>
<mx:RemoteObject id="FlexDnDRemoteService"
showBusyCursor="true"
destination="FlexDnD">
<mx:method name="process"
result="resultHandler(event)"
fault="faultHandler(event)"/>
</mx:RemoteObject>
</mx:Application>
Thanks,
RajivYa , i have searched and have used the same code.
But needed to customize few things like:
stop dnd in same tree
drop some item into a folder ..( onto it ) etc
have achieved the same .. but this issue ..
i think the tree dataprovider (contents internally is not being updated .. only the UI)
any suggestions ?
- Rajiv -
Drag and Drop items among JList
Hi,
I want to drag item from one JList and drop into another JList using JFrame in java Swing. Please provide me code for this.
Thanks
NitinYou need to implement a drag-and-drop (dnd) behaviour between your swing components.
Like most programming tasks it looks harder than it really is. Basically you need a DragSource and a DropTarget with a Transferable object in between. This Transferable object is the object from your list.
Here is Sun's tutorial on it... http://java.sun.com/docs/books/tutorial/dnd/
Good luck. -
Drag-and-drop tree list from files/folder
Hello all. I'm new to Flex and I'm looking for some help or
for someone to point me in the right direction. I want to write a
simple AIR application to accept a multiple text files (or a folder
full of text files) when the files/folder is dragged into a tree
list. The file/folder name will be the node name. When selected,
the contents of the file will be displayed in a text area. The text
file will contain a 4 x 4 number matrix with each column separated
by a tab and each row separated by a return. (I plan on plotting
the numbers in the matrix in the future).
What I'm most confused about is how to go about
dragging-and-dropping files into a tree list and creating item
names based on the file/folder name? And does the file content need
to go into an array collection?
Maybe I'm going about this in a difficult way. If there is an
easier way, I'd appreciate it if someone could share. Thank you
all.I have the same problema and I´m not able to find the reason.
The solution to get the event raised has been to copy configurations from wd standard appl FPM_TEST_DND_FORM and use my own Z feeder class : all seems to work perfectly , but , if I try to do it from scratch the event FPM_DROP_COMPLETED it´s not raised .
I´ve compared both configurations/class ( the one that I´ve done from scratch that it doesn´t raise the event and the one that I´ve adapted copying from standard that it raises perfectly the event) and I haven´t seen any difference (maybe I haven´t found) . -
List display update labelfunction after drag and drop
I have two list boxes. I have drag and drop enabled and depending upon whether an item has been already dragged to the right box, I want its display in the left box to change (gray out). I have the label function working fine but it's always one item behind, i.e., when I drop an item in the right side box, it's not grayed in the left box until the next action.
I've tried after the drop things such as:
dp.refresh()
leftSideBox.validateNow();
Anything else I can do to get the left side box to re-run the label function for the dataprovider as soon as the drop is done?Wow. It's almost as if you knew the answer. Thanks.
-
JList drag and drop to reorder items
I like to see a implementation of a JList supporting drag and drop to reorder items. The solution has to work with any object type in the datamodel.
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
public class ReorderList {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new ReorderList().makeUI();
public void makeUI() {
Object[] data = {"One", "Two", "Three", "Four", "Five",
"Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve"
DefaultListModel model = new DefaultListModel();
for (Object object : data) {
model.addElement(object);
JList list = new JList(model);
MouseAdapter listener = new ReorderListener(list);
list.addMouseListener(listener);
list.addMouseMotionListener(listener);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200, 200);
frame.add(new JScrollPane(list));
frame.setLocationRelativeTo(null);
frame.setVisible(true);
class ReorderListener extends MouseAdapter {
private JList list;
private int pressIndex = 0;
private int releaseIndex = 0;
public ReorderListener(JList list) {
if (!(list.getModel() instanceof DefaultListModel)) {
throw new IllegalArgumentException("List must have a DefaultListModel");
this.list = list;
@Override
public void mousePressed(MouseEvent e) {
pressIndex = list.locationToIndex(e.getPoint());
@Override
public void mouseReleased(MouseEvent e) {
releaseIndex = list.locationToIndex(e.getPoint());
if (releaseIndex != pressIndex && releaseIndex != -1) {
reorder();
@Override
public void mouseDragged(MouseEvent e) {
mouseReleased(e);
pressIndex = releaseIndex;
private void reorder() {
DefaultListModel model = (DefaultListModel) list.getModel();
Object dragee = model.elementAt(pressIndex);
model.removeElementAt(pressIndex);
model.insertElementAt(dragee, releaseIndex);
}edit Reduced a few LoC
Edited by: Darryl.Burke -
Can you drag and drop within the same list*?
*without completely strange things happening?
It seems like this ought to be fairly straight forward. This
code is taken from the Flex 2 Component Explorer and I've just
added a few Drag and Drop parameters to the list. It doesn't quite
work. The items are duplicated, not selected, selectable. The
behavior is a bit erratic.
It seems very natural to want to be able to re-order a list
using drag and drop so it seems like it should be easy. Obviously,
I could create a second, empty list--but that would take up
valuable screen real estate. I've seen a few posts about this and
none of them were answered so either the solution is obvious
(please share) or it's impossible (please share).
Cheers,
Steve
<?xml version="1.0"?>
<!-- Simple example to demonstrate the List Control -->
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
[Bindable]
public var selectedItem:Object;
]]>
</mx:Script>
<mx:Model id="mystates">
<states>
<state label="Alabama" data="AL"/>
<state label="Alaska" data="AK"/>
<state label="Arizona" data="AZ"/>
<state label="Arkansas" data="AR"/>
<state label="California" data="CA"/>
<state label="Colorado" data="CO"/>
<state label="Connecticut" data="CT"/>
</states>
</mx:Model>
<mx:Panel title="List Control Example" height="75%"
width="75%"
paddingTop="10" paddingBottom="10" paddingLeft="10"
paddingRight="10">
<mx:Label text="Select a state to see its
abbreviation."/>
<mx:List id="source" width="100%" color="blue"
dataProvider="{mystates.state}"
change="this.selectedItem=List(event.target).selectedItem"
dragEnabled="true"
dropEnabled="true"
dragMoveEnabled="true"/>
<mx:VBox width="100%">
<mx:Label text="Selected State:
{selectedItem.label}"/>
<mx:Label text="State abbreviation:
{selectedItem.data}"/>
</mx:VBox>
</mx:Panel>
</mx:Application>The answer is, yes you can. However, I'm not sure why this
makes a difference.
I added creationComplete="init();" to the application tag.
<em>Removed the model</em> and implemented this method:
public function init(): void {
source.dataProvider = [
{label: "Alabama", data: "AL"},
{label: "Alaska", data: "AK"},
{label: "Arizona", data: "AZ"},
{label: "California", data: "CA"},
{label: "Colorado", data: "CO"},
{label: "Connecticut", data: "CT"}
and removed the dataProvider attribute from the List tag.
Can anyone tell me why the one works and the other
doesn't?
Maybe you are looking for
-
Case sensitive statement in the select-statement
Hi All, i have a table in the abap-dictionary filled with names...when i try to select them with the select-statement with condition: table-name_column like 'some_name' I have encountered some problems...the inquiry is case-sensitive. What i want to
-
Upgrade to OS 10.4.10 and iTunes 7.3.1 - has caused iTunes to not work
Since upgraging to the new OS various parts of iTunes don't seem to work. Anyone else having the same problem? I can't play movies in iTunes, add new movies to iTunes. Podcasts aren't downloading. It goes through the download process but doesn't actu
-
I purchased an AE to connect to my Zeppelin(old type) to enable me to play my itunes library through it using Ipad/Iphone remote as i do with Apple TV/Mac etc but despite all efforts(spent 2 hours on phone with Apple support) still will not connect.
-
I have a 2010 macbook pro 13" that I occasionally hook up to a 19" external monitor using the miniport adapter for the VGA cable. With Mavericks, will I be able to power my 13" screen along with the 19" plugged in and an additional monitor hooked up
-
Facing error updating iPhoto and downloading xCode from Apple store
hi there, im trying to update my iPhoto, it was downloading perfectly well for more than an hour, then when i came back to check on its' progress it has stopped downloading and the message "An error has occured" was next to it, tried to update it sev