🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #9964

Drag and Drop from JTree to JComboBox problem

#9964
From: Jeff Marendo
Date: Mon, 20 Dec 1999 00:00
89 lines
3953 bytes
Hello,

Right now I have to versions where I'm trying to get the string values from
a JTree copied into a JComboBox (that already has some strings in it) by
using Java's drag and drop functionality.  My main two classes for this are
JDragTree and JDropComboBox which are extended from JTree and JComboBox
respectively.

The first version I have has JDragTree implementing DragGestureListener and
DragSourceListener; and, JDropComboBox implementing DropTargetListener.  The
dragging functionality from my tree class seems to be working fine, but my
DropTarget associated with my combo box class seems to be rejecting the
operation.  Two things worth noting about that:

One is that my dragOver method in JDragTree isn't being called, which it
should be from what I've read if the drop operation completes successfully.
Two is that none of the functions for the DropTargetListener in
JDropComboBox are being called at all.  The DropTarget (called dropTarget in
my code) declared in JDropComboBox is active b/c I have a check in the
class's constructor that checks it by calling DropTarget's isActive()
function.  I'm trying to instantiate the DropTarget in JDropComboBox's
constructor like this:

public class JDropComboBox extends JComboBox
  implements DropTargetListener {
DropTarget dropTarget = null;
public JDropComboBox() {
  dropTarget = new DropTarget(this, this);
  setModel(createComboBoxModel);
}
...

createComboBoxModel is set up like this:

private ComboBoxModel createComboBoxModel() {
    String [] temp = {"Gandalf", "Bilbo", "Aragorn", "Frodo", "Gollum"};
    return new ComboBoxModel(temp);
}

I'm using two classes that are designed to be models for my combo box.
ComboBoxModel extends from JDropComboBoxModel, which extends from
DefaultMutableComboBoxModel.  They're set up like this:

import javax.swing.*;

public class ComboBoxModel extends JDropComboBoxModel {
  public ComboBoxModel() {
    super();
  }

  public ComboBoxModel(Object [] items) {
    super(items);
  }
}

import javax.swing.*;

abstract public class JDropComboBoxModel extends DefaultComboBoxModel
  implements MutableComboBoxModel {

  public JDropComboBoxModel() {
    super();
  }

  public JDropComboBoxModel(Object [] items) {
    super(items);
  }
}

I'm not sure what I'm doing wrong with my approach listed above.  I was
reading and found that it's not necessarily good design to have your class
with the dropTarget associated like dropTarget = new DropTarget(this, this),
so my second approach to this involves trying to create a class that
implements DropTargetListener and Transferable.  This is so I can declare a
private variable in my JDropComboBox that represents a drop target listener.
I would then create my dropTarget (in the constructor for JDropComboBox)
like this:

dropTarget = new DropTarget(this, mylistenerclass)

For now, if anyone can help me out by giving me some tips based upon what
you've seen so far, please respond.  I do think the second approach is more
correct, but I was getting an error with my drop target listener class I
created.  I was trying to use a method (isDataFlavorSupported) from
Transferable, and the error said that my listener class should be declared
abstract b/c the transferable method wasn't defined in my listener class.
Any help will be appreciated.  Thanks.

Jeff
Technical Details
Message-ID: <83lih5$rgb11@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,fd5e24c213cbe935,start
X-Google-Attributes: gid111d45,public
From: "Jeff Marendo" <marendoj@commos.com>
Subject: Drag and Drop from JTree to JComboBox problem
Date: 1999/12/20
Message-ID: <83lih5$rgb11@forums.borland.com>
X-Deja-AN: 563026265
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200
Organization: CommTech Corporation
X-MSMail-Priority: Normal
Reply-To: "Jeff Marendo" <marendoj@commos.com>
Newsgroups: borland.public.jbuilder.java.swing