Drag and Drop custom objects

Hi guys.
I just finished reading the Java tutorial on Drag and Drop at http://download.oracle.com/javase/tutorial/uiswing/dnd/index.html.
Unfortunately, there is no note about how to drag and drop a custon object. There is something said on DataFlavor, but not enough to help me.
So I would appreciate it if anyone could tell me the steps to follow when dragging and droping a custom object.
Best regards.
Edmond

I think we can help you, but please post some example/code of what you are trying to achieve.
I made D&D with custom objects, custom icons, etc. and is not so hard ... like I said, post some code ...
RGV

Similar Messages

  • Drag and drop custom object

    Hello,
    I am trying to create a GUI where the user will be able to drag an object (which I have created) from a toolbar button onto a JPanel. I have tried the sun tutorials to no avail. I am unsure exactly what code I should be writing to enable this functionality. I have written a dragmouseadapter which enables drag and drop from the button. I have also written a TransferHandler and Transferable for the object, but again I'm not sure how I should be using these. Can anyone advise me? Hopefully in a sort of step-by-step instruction for setting this up. Thank you.

    You wanted to drag and drop a custom component and you said its done using dragmouseadapter!
    TransferHandler and Transferable are used to transfer the data between the swing components.
    Now, what you want to do? So, we can help!

  • Drag and dropping database objects in Jdev

    I evaluated Visual Cafe and deciding wheather to go with VC or JDev. One of the cool things I noticed in VC is that one can drag and drop database objects in the form using DBNavigator. I haven't seen anything similar in JDev 3.1. Does this or something similar exist in JDev?
    Regards,
    Mark

    Mark,
    Yes, the DB Navigator in Visual Cafe may provide a nice simple look at the database Tables - but so does JDeveloper's Database Navigator - VC may excel in the Drag and Drop functionality - but this is not the real objective. Let me explain...
    When creating a real enterprise level application in Visual Cafe, you begin to discover that DB Navigator along with it's nifty Drag & Drop is no match for JDeveloper's unprecedented level of database integration. JDeveloper's Database related integration includes (but not limited to):
    - JDevelopers Database Navigator
    - Integrated SQLJ environment
    - Tight Business Components for Java (BC4J) integration
    - Wizard driven Form generation (thin & thick)
    - DAC Controls / InfoSwing components
    - Named Connections / Connection Manager
    - WebBeans / JSP Element Wizard
    The closest thing in JDeveloper to what you are referring to in VC is JDeveloper's support for the Design mode which allows you to design both graphical and non-graphical elements. In particular, JDeveloper allows you to design your InfoSwing and InfoProducer components using the Designer - by selecting the component (JavaBean) from the Component Palette and then [Dragging Optional] Dropping it on either the Design Canvas or the Structure pane (lower pane of Navigator window).
    For non-visual elements (such as InfoProducer elements), the Structure pane allows for Creation via Drag & Drop and allows for property setting by using the Property Inspector (Since it is a JavaBean...).
    There are many reasons why JDeveloper provides a much richer and more productive development environment than Visual Cafe. Most have to do with seeking a complete enterprise level solution. JDeveloper adresses the enterprise level application developers needs directly with integration of elements from Tools & Wizards to the integration of a complete application development framework - Oracle Business Components for Java - No other tool can provide you with such a rich and productive development environment.
    John - JDeveloper Team
    null

  • How realize drag and drop of object

    Hi everybody,
    I have a matter, I want to realise a
    VI who makes drag and drop of indicator like a gauge for example.
    For this I used an event structure to
    manage the drag and drop. But the probleme is that with this solution
    i must put the indicator in my program to set the properties node
    (visible or position).
    So the number of indicator that i can
    drop and drag depend of the number of indicator that i declare in my
    soft.
    I want to know if there is an other
    methode to do that.
    Please find attached a VI to show you
    my objectif.
    Attachments:
    gliss dep.vi ‏36 KB

    duplicate post

  • Drag and drop data object  not working in jdev 11.1.1.7

    I am trying to do quote process lab and faced this issue.
    When defining the user task parameter in jdev 11.1.1.7 i am not able to drag and drop the data object in parameter list section.

    Infact i am trying to create a simple BPMN projoect but it doesn't allow the data object to be drag and dropped in the parameter list.
    This same thing was working fine for me in Jdev 11.1.1.6,Is there a bug in jdeve 11.1.1.7 ? Has anyone tested with the latest release?

  • Drag and Drop 2 objects 1 target

    I am fairly new to Flash and trying to create a drag and drop.  I have been following the tutorial here (http://monkeyflash.com/tutorials/flash-drag-and-drop/). One change I made to this tutorial was to have the object disappear when it is dropped on the target.  Following these directions I was able to successfully build a drag and drop with one object to one target.  My question is what if I want to have multiple objects go to the same target?  For example in the tutorial what if I added a second square object and wanted both to go to the one square target.
    Any help would be greatly appreciated!

    As long as the target is still accessible as a target you can drag as many objects to as you want (one at a time).  To help do that, when you drop an object on the target and make it disappear, you either need to make that dropped object go away ( removeChild(dropped) ) so that it is not blocking the way or move the target above the dropped object ( addChild(target) ).

  • Drag and drop List Object[] collection

    is it possible? If we combine JPA entities which are returned then we have to return List<Object[]> collection, e.g. some combination of the fields from Employees and Projects entities is returned by a service

    Not sure what this question is pertaining to. Are you referring to the use of drag and drop in the context of ADF Faces RC with JPA? Or are you describing a design time issue with JPA? Please clarify.
    Thanks,
    RiC

  • Drag and drop custom component

    I have a custom component that is a JPanel with a JTextField and a JButton. The component is a display and chooser for an address. I want to be able to copy the address from one to another with drag and drop.
    Here's what I have so far. The drag starts, but it won't allow to drop on another instance of the same class. MyTransferHandler is a simple subclass of TransferHandler that logs everything so I can watch what is happening. The canImport() method of TransferHandler is never getting called. Any ideas?
    transferHandler = new MyTransferHandler("address");
    setTransferHandler(transferHandler);
    dragListener = new MouseMotionListener() {
    public void mouseDragged(MouseEvent a_evt) {
    if (address != null) {
    TransferHandler l_h = getTransferHandler();
    l_h.exportAsDrag(PanelAddress.this, a_evt, TransferHandler.COPY);
    public void mouseMoved(MouseEvent e) {
    addMouseMotionListener(dragListener);
    txtAddress.addMouseMotionListener(dragListener);

    Figured it out while creating the SSCCE. Needed to set the TransferHandler on the text field and button because they were "hiding" the panel.
    {noformat} MyTransferHandler l_transfer_handler = new MyTransferHandler("address");{noformat}{noformat} setTransferHandler(l_transfer_handler);{noformat}{noformat} txtAddress.setTransferHandler(l_transfer_handler);{noformat}{noformat} btnChoose.setTransferHandler(l_transfer_handler);{noformat}{noformat}{noformat}

  • How to drag and drop a object in an indicator at run time?

    How to drag and drop a picture at run time in a indicator displaying pictures on the front panel. The main thing is that the window is displaying frames continuously?

    Hi Vivman,
    You have duplicated this post here. Please do not post the same question to separate forum post.
    Cheers.
    | Michael K | Project Manager | LabVIEW R&D | National Instruments |

  • Drag and Drop 3D Objects?

    So I'm curious if anyone has an idea about this?
    You cannoth use a Mesh as a DragView currently, so I figured I would created an instance of my object, and drag it once it enters the Target. I cannot find a way to automatically start a mouse press and have it move with the current operation.
    I also cannot serialize TriangleMesh which I use in my Object to map it to a DataFormat.
    I put up a Jira Report here https://javafx-jira.kenai.com/browse/RT-30209
    but I'm curious if anyone has any thoughts on this matter?
    I figure the easiest way would being able to use a Mesh as a view, and be able to drag that mapped data. Granted even without the data I can set it up with DragDone to do what I need, but I would really love the Mesh as a DragView :).

    I was thinking about taking a snapshot yesterday, thanks for the idea!
    Sad to hear it doesn't work too well :(.
    I'm using Imported 3D Mesh's from InteractiveMesh's Importer, I'm not sure how well it would work...
    I also wanted to mention that DragView for a normal 2D Image didn't work if placed in DragOVer, and I believe DragEntered. if done in DragDetected it will display the image. IS this how it's supposed to be done? I potentially like the 3d mesh or an snapshot image to be shown when dropping over a target. Thoughts?
    Edited by: KonradZuse on May 7, 2013 6:38 PM

  • ID CS6 drag and drop anchored object - unable to get blue square

    Hi,
    I am a long time and intensive user of CS.
    A week ago or so, the blue square for dragging an anchored object disappeared.
    I have to do it manually. Troublesome since I am in the process of producing a number of ebooks.
    Any ideas? Thanks (I tried restarting the preferences, to no avail)
    (I publish in the pdf section, I cannot see any epub section )

    Hi has anyone an idea on this   blue square question please? an adobe expert maybe? thanks a lot

  • Drag and Drop / Movable Object

    Dear All,
    I am required to create an application which draws multiple objects and they are interconnected with arrows or lines. Furthermore, the objects must be able to be drag away from the rest with maintaining the arrows which link it to the rest of the objects.
    1. Any suggestion where I should I start ?
    2. Is it better to use canvas or DnD ?
    Thank you for your time.
    Regards,
    Mustafa

    Vrijmetse wrote:
    So are you saying that DnD is not an option at all ? I'd say you completely missed the point.
    *1) Ways to position objects/components in a rendering:*
    - MouseListener
    - D'n'D
    - Spinners provided to set component position and size
    - Scrying
    *2) Things to render objects/components on:*
    - java.awt.Canvas
    - *(whatever).swt.Canvas* (<-assuming that is what you meant by 'Canvas')
    - javax.swing.JPanel
    - skin (tattoo)
    So if we change "I have to go to work, should I take the bus or wear green socks?" to "I have to offer an exact-layout rendering for objects, should I offer ways to position the objects or things to render them on?".
    Does that second question 'make sense' to you?

  • I can't drag and drop text objects onto a report

    now i cant seem to insert anything on to an existing report, i am very new to crystal and have searched a couple of forums, i will keep searching the forums, but if someone has a link or any advice that would be great, maybe its a setting i unknowingly have checked?

    If you selected Read only option for the report. Change the option using :
    File->Report options-> (un check "Read only")
    If you are not able to drag fields on only sections. then go to section expert and if a particular section is selected as read only,then remove the read only option there.
    I hope this may help you.
    Regards,
    Parsa.

  • How do I drag and drop multiple objects in a mask?

    I’ve been working on a flash simulator to show what our night vision product would look like in the dark.  I have been successful in making it work with the following code below.  Yet I cannot add a "reticle" image (or symbol) to the draggable mask to make it work.  Can someone help me with the code?  I looked for hours on the internet and I cannot get it to work.  I am new to Flash but am starting to learn as much as I can.
    Actionscript 3 Code:
    img_nv.mask = mask_mc;
    mask_mc.buttonMode = true;
    mask_mc.addEventListener(MouseEvent.MOUSE_DOWN, dF);
    stage.addEventListener(MouseEvent.MOUSE_UP, dropF);
    function dF(event:MouseEvent):void{
              mask_mc.startDrag();
    function dropF(event:MouseEvent):void{
              mask_mc.stopDrag();

    use a loop (like enterframe) and update the reticle's position to match mask_mc's position.
    mg_nv.mask = mask_mc;
    mask_mc.buttonMode = true;
    // eg, if you add reticle_mc to the stage in the authoring environment
    removeChild(reticle_mc);
    mask_mc.addEventListener(MouseEvent.MOUSE_DOWN, dF);
    stage.addEventListener(MouseEvent.MOUSE_UP, dropF);
    function dF(event:MouseEvent):void{
    addChild(reticle_mc);
    this.addEventListener(Event.ENTER_FRAME,reticleF);
              mask_mc.startDrag();
    function dropF(event:MouseEvent):void{
    removeChild(reticle_mc);
    this.removeEventListener(Event.ENTER_FRAME,reticleF);
              mask_mc.stopDrag();
    function reticleF(e:Event):void{
    reticle_mc.x=mask_mc.x;  // assuming they both have the same reg points (like the center)
    reticle_mc.y=mask_mc.y;

  • Drag and Drop objects with JavaFX properties

    Has anyone tried to implement drag and drop functionality with objects containing JavaFX properties? The issue I'm running into is that the objects appear to need to be serializable, and the JavaFX properties are not serializable. I can implement Externalizable instead of Serializable, and basically serialize the values contained by the FX properties, but of course I lose any bindings by doing this (as the listeners underlying the bindings are not serialized).
    The [url http://docs.oracle.com/javafx/2/api/javafx/scene/input/Clipboard.html]javadocs for Clipboard state "In addition to the common or built in types, you may put any arbitrary data onto the clipboard (assuming it is either a reference, or serializable. See more about references later)" but I don't see any further information about references (and at any rate, this doesn't really make sense since anything that's serializable would be a reference anyway). Is there a special DataFormat I can use to specify a reference in the local JVM so the reference gets passed without serialization?
    I know this might not make sense without a code example; I just thought someone might have come across this closely enough to recognize the problem. I'll try to post a code example tonight...

    Here's pretty much the simplest example I can come up with. I have a real-world example of needing to do this, but the object model for the real example is quite a bit more complex.
    For the toy example, imagine we have a list of projects, some employees, and we want to assign each project to one or more employees. I have a Project class with a title and assignee. (In real life you can imagine other properties; due date, status, etc.) I'll keep a ListView with a bunch of unassigned projects (titles but assignees equal to null) and then a ListView for each of the employees.
    To assign a project to an employee, the user should be able to drag from the "master" list view to one of the employee list views. When the project is dropped, we'll create a new project, set the assignee, and bind the title of the new project to the title of the project which was dragged. (Remember we want to be able to assign a single project to multiple employees.)
    So here's the first shot:
    A couple of simple model classes
    Project.java
    import java.io.Externalizable;
    import java.io.IOException;
    import java.io.ObjectInput;
    import java.io.ObjectOutput;
    import javafx.beans.property.ObjectProperty;
    import javafx.beans.property.SimpleObjectProperty;
    import javafx.beans.property.SimpleStringProperty;
    import javafx.beans.property.StringProperty;
    public class Project {
         private final StringProperty title ;
         private final ObjectProperty<Employee> assignee ;
         public Project(String title) {
              this.title = new SimpleStringProperty(this, "title", title);
              this.assignee = new SimpleObjectProperty<Employee>(this, "assignee");
         public Project() {
              this("");
         public StringProperty titleProperty() {
              return title ;
         public String getTitle() {
              return title.get() ;
         public void setTitle(String title) {
              this.title.set(title);
         public ObjectProperty<Employee> assigneeProperty() {
              return assignee ;
         public Employee getAssignee() {
              return assignee.get();
         public void setAssignee(Employee assignee) {
              this.assignee.set(assignee);
         @Override
         public String toString() {
              String t = title.get();
              Employee emp = assignee.get();
              if (emp==null) {
                   return t;
              } else {
                   return String.format("%s (%s)", t, emp.getName()) ;
    }Employee.java
    import java.io.Externalizable;
    import java.io.IOException;
    import java.io.ObjectInput;
    import java.io.ObjectOutput;
    import javafx.beans.property.SimpleStringProperty;
    import javafx.beans.property.StringProperty;
    public class Employee {
         private StringProperty name ;
         public Employee(String name) {
              this.name = new SimpleStringProperty(this,"name", name);
         public StringProperty nameProperty() {
              return name ;
         public String getName() {
              return name.get();
         public void setName(String name) {
              this.name.set(name);
    }and the application
    DnDExample.java
    import javafx.application.Application;
    import javafx.beans.value.ChangeListener;
    import javafx.beans.value.ObservableValue;
    import javafx.collections.ObservableList;
    import javafx.event.EventHandler;
    import javafx.scene.Scene;
    import javafx.scene.control.Label;
    import javafx.scene.control.ListCell;
    import javafx.scene.control.ListView;
    import javafx.scene.control.TextField;
    import javafx.scene.input.ClipboardContent;
    import javafx.scene.input.DataFormat;
    import javafx.scene.input.DragEvent;
    import javafx.scene.input.Dragboard;
    import javafx.scene.input.MouseEvent;
    import javafx.scene.input.TransferMode;
    import javafx.scene.layout.HBox;
    import javafx.scene.layout.VBox;
    import javafx.stage.Stage;
    import javafx.util.Callback;
    public class DnDExample extends Application {
         private static final DataFormat PROJECT_DATA_FORMAT = new DataFormat("com.example.project"); // is there something special I can use here?
         @Override
         public void start(Stage primaryStage) {
              final HBox root = new HBox(5);
              final ListView<Project> allProjects = new ListView<Project>();
              final Employee fred = new Employee("Fred");
              final Employee ginger = new Employee("Ginger");
              final ListView<Project> fredsProjects = new ListView<Project>();
              final ListView<Project> gingersProjects = new ListView<Project>();
              final VBox employeeLists = new VBox(5);
              employeeLists.getChildren().addAll(new Label("Fred's Projects"), fredsProjects, new Label("Ginger's Projects"), gingersProjects);
              root.getChildren().addAll(allProjects, employeeLists);
              allProjects.setCellFactory(new Callback<ListView<Project>, ListCell<Project>>() {
                   @Override
                   public ListCell<Project> call(ListView<Project> listView) {
                        return new AllProjectListCell();
              allProjects.setEditable(true);
              final EventHandler<DragEvent> dragOverHandler = new EventHandler<DragEvent>() {
                   @Override
                   public void handle(DragEvent dragEvent) {
                        if (dragEvent.getDragboard().hasContent(PROJECT_DATA_FORMAT)) {
                             dragEvent.acceptTransferModes(TransferMode.COPY);
              fredsProjects.setOnDragOver(dragOverHandler);
              gingersProjects.setOnDragOver(dragOverHandler);
              fredsProjects.setOnDragDropped(new DragDropHandler(fred, fredsProjects.getItems()));
              gingersProjects.setOnDragDropped(new DragDropHandler(ginger, gingersProjects.getItems()));
              allProjects.getItems().addAll(new Project("Implement Drag and Drop"), new Project("Fix serialization problem"));
              Scene scene = new Scene(root, 600, 400);
              primaryStage.setScene(scene);
              primaryStage.show();
         public static void main(String[] args) {
              launch(args);
         private class DragDropHandler implements EventHandler<DragEvent> {
              private final Employee employee ;
              private final ObservableList<Project> itemList;
              DragDropHandler(Employee employee, ObservableList<Project> itemList) {
                   this.employee = employee ;
                   this.itemList = itemList ;
              @Override
              public void handle(DragEvent event) {
                   Dragboard db = event.getDragboard();
                   if (db.hasContent(PROJECT_DATA_FORMAT)) {
                        Project project = (Project) db.getContent(PROJECT_DATA_FORMAT);
                        Project assignedProject = new Project();
                        assignedProject.titleProperty().bind(project.titleProperty());
                        assignedProject.setAssignee(employee);
                        itemList.add(assignedProject);
         private class AllProjectListCell extends ListCell<Project> {
              private TextField textField ;
              private final EventHandler<MouseEvent> dragDetectedHandler ;
              AllProjectListCell() {               
                   this.dragDetectedHandler = new EventHandler<MouseEvent>() {
                        @Override
                        public void handle(MouseEvent event) {
                             Dragboard db = startDragAndDrop(TransferMode.COPY);
                             ClipboardContent cc = new ClipboardContent();
                             cc.put(PROJECT_DATA_FORMAT, getItem());
                             db.setContent(cc);
                             event.consume();
                   this.setEditable(true);
              @Override
              public void updateItem(final Project project, boolean empty) {
                   super.updateItem(project, empty);
                   if (empty) {
                        setText(null);
                        setGraphic(null);
                        setOnDragDetected(null);
                   } else if (isEditing()) {
                        if (textField != null) {
                             textField.setText(getItem().getTitle());
                        setText(null) ;
                        setOnDragDetected(null);
                        setGraphic(textField);                    
                   } else {
                        setText(project.getTitle());
                        setOnDragDetected(dragDetectedHandler);
              @Override
              public void startEdit() {
                   super.startEdit();
                   if (!isEmpty()) {
                        textField = new TextField(getItem().getTitle());
                        textField.setMinWidth(this.getWidth()-this.getGraphicTextGap());
                        textField.focusedProperty().addListener(new ChangeListener<Boolean>() {
                             @Override
                             public void changed(
                                       ObservableValue<? extends Boolean> observable,
                                       Boolean oldValue, Boolean newValue) {
                                  if (! newValue) {
                                       getItem().setTitle(textField.getText());
                                       commitEdit(getItem());
                        setText(null);
                        setGraphic(textField);
                        setOnDragDetected(null);
              @Override
              public void cancelEdit() {
                   super.cancelEdit();
                   if (!isEmpty()) {
                        setText(getItem().getTitle());
                        setGraphic(null);
                        setOnDragDetected(dragDetectedHandler);
                   } else {
                        setText(null);
                        setGraphic(null);
                        setOnDragDetected(null);
              @Override
              public void commitEdit(Project project) {
                   super.commitEdit(project);
                   if (!isEmpty()) {
                        setText(getItem().getTitle());
                        setGraphic(null);
                        setOnDragDetected(dragDetectedHandler);
    }If you try to drag from the list on the left to one of the lists on the right, it will fail pretty quickly and tell you that the data need to be Serializable.
    Simply adding "implements Serializable" to the Project and Employee classes doesn't work, as you find that SimpleStringProperty and SimpleObjectProperty are not Serializable. So instead I can use Externalizable:
    public class Project implements Externalizable {
    @Override
         public void writeExternal(ObjectOutput out) throws IOException {
              out.writeObject(title.get());
              out.writeObject(assignee.get());
         @Override
         public void readExternal(ObjectInput in) throws IOException,
                   ClassNotFoundException {
              setTitle((String)in.readObject());
              setAssignee((Employee)in.readObject());
    }and
    public class Employee implements Externalizable {
         @Override
         public void writeExternal(ObjectOutput out) throws IOException {
              out.writeObject(name.get());
         @Override
         public void readExternal(ObjectInput in) throws IOException,
                   ClassNotFoundException {
              setName((String) in.readObject());
    }This makes the drag and drop work, but if you drop a project on one of the employee lists, then edit the project title in the master list, the binding is not respected. This is because deserialization creates a new SimpleStringProperty for the title, which is not the property to which the title of the new Project object is bound.
    What I really want to do is to be able to drag and drop an object within the same JVM simply by passing the object by reference, rather than by serializing it. Is there a way to do this? Is there some DataFormat type I need?

Maybe you are looking for

  • Can't watch videos, get a green screen only

    Hi, I can watch videos with MSN, but when I try to watch you tube, cbs or any other site,  get a green screen. I've enable flash and shockwave but still nothing. Help!

  • Pricing approval process in SD

    Hi All, I have a business requirement as below: 1) Whenever any new condition record is maintained using t-code VK11 and ZSD01(Z Transaction for maintaining specific pricing), it should trigger mail to respective authorised manager for approval. 2) T

  • Why does TimeMachine say the disk is full when it isn't?

    Hello! A lot of my backups recently have been failing because TimeMachine says the disk is full, when that simply isn't true. As of right now, I have 1.18 TB available of 2 TB. Why do my backups fail even when sufficient space is there? Thank you so

  • 2 Xserves, 1 XRaid, no Xsan or Masked LUN - Options?

    Hello, we've got an original Xserve hooked up to an XRaid. The setup works great, but we're going to buy another Xserve and I'd like to set something for failover. I thought we would just get a fiber switch, hook up the XRaid and both Xserves and we'

  • ORA-12547 when using sqlpus or svrmgrl as any user except oracle

    I have Oracle 8.1.7 and Oracle 9.0.1 installed on a Slackware 8.0 Linux box. It used to work fine, but something changed one day. I have tried with the Oracle 8 and Oracle 9 binaries with the same problem. If I try svrmgrl or sqlplus as oracle, all i