How to drag and drop tab nodes between tab panes

I'm working on example from this tutorial( Drag-and-Drop Feature in JavaFX Applications | JavaFX 2 Tutorials and Documentation ). Based on the tutorial I want to drag tabs between two tabs. So far I managed to create this code but I need some help in order to finish the code.
Source
tabPane = new TabPane();
Tab tabA = new Tab();
   Label tabALabel = new Label("Main Component");
tabPane.setOnDragDetected(new EventHandler<MouseEvent>()
            @Override
            public void handle(MouseEvent event)
                /* drag was detected, start drag-and-drop gesture*/
                System.out.println("onDragDetected");
                /* allow any transfer mode */
                Dragboard db = tabPane.startDragAndDrop(TransferMode.ANY);
                /* put a string on dragboard */
                ClipboardContent content = new ClipboardContent();
                content.put(DataFormat.PLAIN_TEXT, tabPane);
                db.setContent(content);
                event.consume();
What is the proper way to insert the content of the tab as object? Into the tutorial simple text is transferred. How I must modify this line content.put(DataFormat.PLAIN_TEXT, tabPane);?
And what is the proper way to insert the tab after I drag the tab:
Destination
tabPane.setOnDragDropped(new EventHandler<DragEvent>()
            @Override
            public void handle(DragEvent event)
                /* data dropped */
                /* if there is a string data on dragboard, read it and use it */
                Dragboard db = event.getDragboard();
                boolean success = false;
                if (db.hasString())
                    //tabPane.setText(db.getString());
                    Tab tabC = new Tab();
                    tabPane.getTabs().add(tabC);
                    success = true;
                /* let the source know whether the string was successfully
                 * transferred and used */
                event.setDropCompleted(success);
                event.consume();
I suppose that this transfer can be accomplished?
Ref javafx 2 - How to drag and drop tab nodes between tab panes - Stack Overflow

I would use a graphic (instead of text) for the Tabs and call setOnDragDetected on that graphic. That way you know which tab is being dragged. There's no nice way to put the Tab itself into the dragboard as it's not serializable (see https://javafx-jira.kenai.com/browse/RT-29082), so you probably just want to store the tab currently being dragged in a property.
Here's a quick example; it just adds the tab to the end of the current tabs in the dropped pane. If you wanted to insert it into the nearest location to the actual drop you could probably iterate through the tabs and figure the coordinates of each tab's graphic, or something.
import java.util.Random;
import javafx.application.Application;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.DragEvent;
import javafx.scene.input.Dragboard;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class DraggingTabPane extends Application {
  private static final String TAB_DRAG_KEY = "tab" ;
  private ObjectProperty<Tab> draggingTab ;
@Override
  public void start(Stage primaryStage) {
  draggingTab = new SimpleObjectProperty<>();
  TabPane tabPane1 = createTabPane();
  TabPane tabPane2 = createTabPane();
  VBox root = new VBox(10);
  root.getChildren().addAll(tabPane1, tabPane2);
  final Random rng = new Random();
  for (int i=1; i<=8; i++) {
    final Tab tab = createTab("Tab "+i);
    final StackPane pane = new StackPane();
      int red = rng.nextInt(256);
      int green = rng.nextInt(256);
      int blue = rng.nextInt(256);
    String style = String.format("-fx-background-color: rgb(%d, %d, %d);", red, green, blue);
    pane.setStyle(style);
    final Label label = new Label("This is tab "+i);
    label.setStyle(String.format("-fx-text-fill: rgb(%d, %d, %d);", 256-red, 256-green, 256-blue));
    pane.getChildren().add(label);
    pane.setMinWidth(600);
    pane.setMinHeight(250);
    tab.setContent(pane);
    if (i<=4) {
      tabPane1.getTabs().add(tab);
    } else {
      tabPane2.getTabs().add(tab);
  primaryStage.setScene(new Scene(root, 600, 600));
  primaryStage.show();
  public static void main(String[] args) {
  launch(args);
  private TabPane createTabPane() {
    final TabPane tabPane = new TabPane();
    tabPane.setOnDragOver(new EventHandler<DragEvent>() {
      @Override
      public void handle(DragEvent event) {
        final Dragboard dragboard = event.getDragboard();
        if (dragboard.hasString()
            && TAB_DRAG_KEY.equals(dragboard.getString())
            && draggingTab.get() != null
            && draggingTab.get().getTabPane() != tabPane) {
          event.acceptTransferModes(TransferMode.MOVE);
          event.consume();
    tabPane.setOnDragDropped(new EventHandler<DragEvent>() {
      @Override
      public void handle(DragEvent event) {
        final Dragboard dragboard = event.getDragboard();
        if (dragboard.hasString()
            && TAB_DRAG_KEY.equals(dragboard.getString())
            && draggingTab.get() != null
            && draggingTab.get().getTabPane() != tabPane) {
          final Tab tab = draggingTab.get();
          tab.getTabPane().getTabs().remove(tab);
          tabPane.getTabs().add(tab);
          event.setDropCompleted(true);
          draggingTab.set(null);
          event.consume();
    return tabPane ;
  private Tab createTab(String text) {
    final Tab tab = new Tab();
    final Label label = new Label(text);
    tab.setGraphic(label);
    label.setOnDragDetected(new EventHandler<MouseEvent>() {
      @Override
      public void handle(MouseEvent event) {
        Dragboard dragboard = label.startDragAndDrop(TransferMode.MOVE);
        ClipboardContent clipboardContent = new ClipboardContent();
        clipboardContent.putString(TAB_DRAG_KEY);
        dragboard.setContent(clipboardContent);
        draggingTab.set(tab);
        event.consume();
    return tab ;

Similar Messages

  • How to drag and drop an Image between two JPanels inside a Split Pane

    I'm tring to do that, and my actual problem is as follows:
    I drag the Image from the bottomPanel but I can't drop it in the topPanel, I'm using this classes:
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.border.*;
    import java.awt.dnd.*;
    import java.awt.datatransfer.*;
    import java.awt.image.*;
    public class MoveableComponentsContainer extends JSplitPane {     
         public DragSource dragSource;
         public DropTarget dropTarget;
    public JPanel topPanel = new JPanel();
    public JPanel bottomPanel = new JPanel();
         public int ancho;
    public int alto;
    public MoveableLabel lab1,lab2,lab3,lab4;
    public Icon ico1, ico2,ico3,ico4;
    private static BufferedImage buffImage = null; //buff image
         private static Point cursorPoint = new Point();
    public int getMaximumDividerLocation() {
    return ( ( int ) ( alto * .85 ) );
    public int getMinimumDividerLocation() {
    return( ( int ) ( alto * .85 ) );
         public MoveableComponentsContainer(int Weight, int Height ) {
    alto = Height;
    ancho = Weight;
    setOrientation( VERTICAL_SPLIT);
    setDividerSize(2);
    getMaximumDividerLocation();
    getMinimumDividerLocation();
    setPreferredSize(new Dimension( (int) ( Weight * .99 ), (int) ( Height * .94 ) ) );
    setDividerLocation( getMaximumDividerLocation() );
    System.out.println( " getDividerLocation() = " + getDividerLocation() );
    topPanel.setName("topPanel");
    bottomPanel.setName("bottomPanel");
    bottomPanel.setPreferredSize( new Dimension( (int) ( Weight * .99 ), (int) ( ( Height * .94 ) * .15 ) ) );
    bottomPanel.setMaximumSize( new Dimension( (int) ( Weight * .99 ), (int) ( ( Height * .94 ) * .15 ) ) );
    bottomPanel.setMinimumSize( new Dimension( (int) ( Weight * .99 ), (int) ( ( Height * .94 ) * .15 ) ) );
    topPanel. setPreferredSize( new Dimension( (int) ( Weight * .99 ), (int) ( ( Height * .94 ) * .85 ) ) );
    topPanel. setMaximumSize( new Dimension( (int) ( Weight * .99 ), (int) ( ( Height * .94 ) * .85 ) ) );
    topPanel. setMinimumSize( new Dimension( (int) ( Weight * .99 ), (int) ( ( Height * .94 ) * .85 ) ) );
    bottomPanel.setEnabled(true);
    bottomPanel.setVisible(true);
    bottomPanel.setBackground( new Color( 57,76,123 ) );
    topPanel. setEnabled(true);
    topPanel. setVisible(true);
    topPanel. setBackground( new Color( 57,76,123 ) );
    setBottomComponent( bottomPanel );
    setTopComponent( topPanel );
    setOneTouchExpandable( false );
    bottomPanel.setBorder(BorderFactory.createTitledBorder("Drag and Drop Test"));
              setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED, Color.white, Color.gray));
    bottomPanel.setLayout( new FlowLayout() );
    topPanel.setLayout(new FlowLayout());
              addMoveableComponents();
         private void addMoveableComponents() {
    ico1 = new ImageIcon( "/usr/local/installers/java/lll/DnD/switchm.gif");
    lab1 = new MoveableLabel("Centrales", ico1, topPanel );
    lab1.setName("labelOne");
    bottomPanel.add( lab1 );
              lab2 = new MoveableLabel("Destinos", ico1, topPanel);
    lab2.setName("labelTwo");
              bottomPanel.add( lab2 );
              lab3 = new MoveableLabel("Registros", ico1, topPanel );
    lab3.setName("labelThree");
              bottomPanel.add( lab3 );
              lab4 = new MoveableLabel("Parametros", ico1, topPanel);
    lab4.setName("labelFour");
              bottomPanel.add( lab4 );
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.border.*;
    import java.awt.dnd.*;
    import java.awt.datatransfer.*;
    public class MoveableLabel extends JLabel implements Transferable {
    final static int FILE = 0;
    final static int STRING = 1;
    final static int IMAGE = 2;
    DataFlavor flavors[] = { DataFlavor.javaFileListFlavor,
    DataFlavor.stringFlavor,
    DataFlavor.imageFlavor };
    public JPanel PanelDestino;
    public JPanel PanelOrigen;
    public DropTarget dropTarget;
    public DropTargetListener dropTargetLis;
         private static final Border border = BorderFactory.createLineBorder(Color.black, 1);
         public MoveableLabel(String text, Icon ic, JPanel DestPanel) {
              super( text, ic, TRAILING);
    PanelDestino = DestPanel;
              MouseEventForwarder forwarder = new MouseEventForwarder();
              addMouseListener(forwarder);
              addMouseMotionListener(forwarder);
              setBorder(border);
              setBounds(0,0,50,100);
              setOpaque(true);
    setTransferHandler(new TransferHandler("text"));
    setBackground( new Color( 57,76,123 ) );
    public synchronized DataFlavor[] getTransferDataFlavors() {
         return flavors;
    public boolean isDataFlavorSupported(DataFlavor flavor) {
    boolean b = false;
    b |= flavor.equals(flavors[ FILE ]);
    b |= flavor.equals(flavors[STRING]);
    b |= flavor.equals(flavors[ IMAGE]);
    return (b);
    public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, java.io.IOException {
    return this;
         final class MouseEventForwarder extends MouseInputAdapter {
              public void mousePressed(MouseEvent e) {
                   Container parent = getParent();
    Container brother = (Container)PanelDestino;
    System.out.println( "Parent 1 = " + parent.getName() );
    System.out.println( "Destino 1 = " + brother.getName() );
    JComponent c = (JComponent) e.getSource();
    System.out.println( "getsource() = " + c.getName() );
    TransferHandler th = c.getTransferHandler();
    th.exportAsDrag( c, e, TransferHandler.COPY_OR_MOVE );
    dropTarget = getDropTarget();
    System.out.println( "dropTarget.getComponent().getName() = " + dropTarget.getComponent().getName() );
    for ( int a=0; a < parent.getComponentCount(); a++ ) {
    parent.getComponent( a ).setEnabled( false );
    brother.setDropTarget( dropTarget );
    System.out.println( "dropTarget.getComponent().getName() = " + dropTarget.getComponent().getName() );
              public void mouseReleased(MouseEvent e) {
                   Container parent = getParent();
    Container brother = PanelDestino;
    System.out.println( "Parent 2 = " + parent.getName() );
    System.out.println( "Destino 2 = " + PanelDestino.getName() );
    parent.setEnabled( true );
    brother.setEnabled( false );
    for ( int a=0; a < parent.getComponentCount(); a++ ) {
    parent.getComponent( a ).setEnabled( true );
    import java.awt.*;
    import javax.swing.*;
    public class TestDragComponent extends JFrame {
         public TestDragComponent() {
    super("TestDragComponent");
    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension dm = new Dimension();
    dm = tk.getScreenSize();
    System.out.println(dm.height);
    System.out.println(dm.width );
    Container cntn = getContentPane();
    cntn.setFont(new Font("Helvetica", Font.PLAIN, 14));
    cntn.add(new MoveableComponentsContainer(dm.width,dm.height));
              pack();
              setVisible(true);
         public static void main(String[] args) {
              new TestDragComponent();

    Ok I found the answer to your problem. If you download the tutorial they have the code there it's in one folder. I hope this helps.
    http://java.sun.com/docs/books/tutorial/

  • How drag and drop a node in a TreeView ?

    Hi,
    I want drag and drop a node in a treeview but i don't know how to get this result. I can drag a page item in a treeview or drag a node in a page item but not a node in another.
    Can you help me ?
    Regards,
    Damien Fontaine

    Your implementation of DoAddDragContent() is a little thin looking.
    If you look at the example in the SDK (BscDNDCustomDragSource.cpp) you might need to add at least:
        // we get the data object that represents the drag
        InterfacePtr<IPMDataObject> item(DNDController->AddDragItem(1));
        // no flavor flags
        PMFlavorFlags flavorFlags = 0;
        // we set the type (flavour) in the drag object
        item->PromiseFlavor(customFlavor, flavorFlags);
    Also, check that DoAddDragContent()  is actually being called.

  • How to drag and drop between portlets?

    Howdy!
    Could someone please be kind enough to show me how to drag and drop data between portlets. I want to select an icon, drag it to an application and launch the file associated with the icon in the application.
    I can do it within a portlet with some js functions but when I try it between portlets (on the same page)I see the forbiden sign.
    Thanks
    Jeff Graber

    Hi
    thanks for the advice. However, that is what I had done. Here is the code in the jsp file for the destination portlet and it does not work. If you have any ideas, thanks!
    <%@ page language="java" contentType="text/html;charset=UTF-8"%>
    <%@ taglib uri="netui-tags-databinding.tld" prefix="netui-data"%>
    <%@ taglib uri="netui-tags-html.tld" prefix="netui"%>
    <%@ taglib uri="netui-tags-template.tld" prefix="netui-template"%>
    <netui:html>
    <head>
    <title>
    MS Word Portlet
    </title>
              <script language="JavaScript" src="../js/common.js"></script>
              <script language="JavaScript" src="../js/containers.js"></script>
              <script language="JavaScript" src="../js/document.js"></script>
    </head>
    <body>
    Application Village Portlet
    <p>TextOre
    | <a id="MS Word" ondrop="sendInfo(this.id)" ondragover="fnCancelDefault()"><img src="/Jime/images/WORDY.gif" alt="Drag one or more documents here to open with MS Word" border="0"></img></a>
    | <a id="MS Excel" ondrop="sendInfo     (this.id);" ondragover="fnCancelDefault()"><img src="/Jime/images/EXCELY.gif" alt="Drag one or more documents here to open with MS Excel" border="0"></img></a>
    | <a id="MS PowerPoint" ondrop="sendInfo(this.id);" ondragover="fnCancelDefault()"><img src="/Jime/images/PowerPointY.gif" alt="Drag one or more documents here to open with MS PowerPoint" border="0"></img></a>
    | <a id="Trash" ondrop="sendInfo(this.id);" ondragover="fnCancelDefault()"><img src="/Jime/images/trashcan.gif" alt="Drag one or more documents here to delete" border="0"></img></a>
    </body>
    </netui:html>

  • How to drag and drop user from one node to other node.

    Dear All,
    How to drag and drop user from one node to other node.I tried but no success.
    What are precautions to be taken.
    Cay anybody kindly explain it.
    Thank you.

    Hello, if you had this message you had created BP....
    Now you don't have to user USERS_GEN this transaction is used only in first action, when you create the user in R/3 and then you pass this user to EBP in the organizational structure.
    Now you have to:
    1) Go to PPOMA_BBP
    2) Double click on organizational unit that you want to put this user (purchasing organization or purchasing group box for example)
    3) Select assign button in the top of the functions in the transaction
    4) Click on incorporates -- position
    5) Put userID that you want to add in this organizational unit
    6) Click Save
    Thanks
    Rosa

  • How to drag and drop the af:inputNumberSpinbox in the control panel

    Hi,
    I am using jdev 11.1.1.4.0
    I need the component as <af:inputNumberSpinbox> . Create a data model and how to drag and drop as inputNumberSpinbox in the data control.
    normally drog and drop the particular attribute as inputText box only. I want <af:inputNumberSpinbox>.
    anythig want to change in the view object control hints itself. help me.
    Regards,
    ragupathi S.
    Edited by: Ragu on Jun 22, 2011 4:45 PM

    Hi,
    Can't you drop it as an inputText and then change it in the source to inputNumberSpinbox?
    Regards,
    Stijn.

  • How to drag and drop another swf or fla into a template?

    I am building a flash website for a friend. We are using templates he purchased at flashden.net.
    I normally use wordpress, joomla and other such systems and am familiar with html, php, cgi and such.
    This is my first time dealing with a flash template.
    I have downloaded the trial version of the software and he wants to purchase adobe flash professional for me
    So that we can edit the template and add features he wants in the future.
    The website that sells the templates says you can easily drag and drop addons to templates in flash
    but I am not finding it so easy. Is there somewhere online where I can find a tutuorial on how to step by step
    drag and drop flash files into another template etc.?
    Also, where can I find good tutorials in general? I have downloaded adobe flash for dummies it is not as indepth as I need
    to get a handle on this software.
    Thank you to anyone that offers me any advice,
    David Doherty

    Ned,
    Thank you for responding.
    Flashden.net does claim its a simple drag and drop operation to do this but they have little to know information on the site about the subject and
    having difficulty with the sellers on step by step instructions. They claim it's easy it may be.
    The person I am building the website for had a bad experience with one of the sellers who refused to offer anything but basic instructions and claimed the cost of the software was not worth his time.
    Here are the instructions that were provided:
      Open news_rotator.fla
      Go to library.
      Select and copy NewsRotator movie clip.
      Paste it into your own project’s library.
      Now, you can drag and drop it into your own movie clips.
      Use news.xml to add/remove headlines.
    As you can see from what your telling me this is insufficent information on how to drag and drop this flash into another flash template.
    I will attempt to contact other selers at flashden for information as I have other flash templates we have purchased.
    Thank you,
    David Doherty

  • 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 |

  • How to drag and drop a picture at run time in a window displaying pictures?

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

    vivman,
    So from your description you have a picture control where you've already created an image and you'd like to drag an image around inside of the picture control. This can be done although it is going to take a significant amount of research and programming on your behalf. You can use the drag event in the event handler to find out when the drag occurs and where the cursor is. Then edit the picture as you move your mouse so that when you drop the picture gets updated.
    The even structure is a somewhat advanced topic and the drag and drop feature is one of the more advanced uses of this structure. I would search the example finder (help>>find examples) for "event" and "drag" to see how to use these events. Also you'll want to look at the examples for the picture control.
    Sounds like a cool project! Check out Darren's Weekly Nugget 10/30/2006 this topic (http://forums.ni.com/ni/board/message?board.id=170&message.id=212920). It might prove useful.
    Good luck!
    Chris C
    Chris Cilino
    National Instruments
    LabVIEW Product Marketing Manager
    Certified LabVIEW Architect

  • Can anyone tell me how to drag and drop music to my ipod with the new version of itunes?

    yeah, so this new update *****.
    just hoping someone can tell me how to drag and drop my music onto my ipod like we used to be able to do in the old versions of itunes. THANKS!

    I haven't used it myself, but I've heard about this app.
    http://plumamazing.com/mac/iwatermark
    The are also a bunch in the App store.
    Matt

  • How to drag and drop a sub tree between 2 treeview?

    Suppose I have 2 tree rendered in 2 treeview. Then I want to drag and drop any subtree on any node between the 2 tree.
    For example, in tree 1, if I drag node node1 and drop it on tree 2 node node2. I want all nodes from node1(subtree) moved to node 2 in tree 2.
    How can I do it? Should I code for treeview 1 begindrag event, and code for treeview 2 dragenter event?
    and how to move a sub tree with pb built-in function?

    Hi Kent,
    I have just experimented with drag and drop between treeviews. Below is your bare minimum and caters for one node only. It does not drag any children along. If you drag an item it loses any children. Although it works both ways and within.
    The handle is set in the dragbegin events.
    In the dragdrop events you get source as an argument which is a pointer to the treeview where the drag started.
    You get the node using GetItem ( ref treeviewitem ), then InsertItemSort as a child of the node dropped on.
    NOTE: Must uncheck DisableDragAndDrop property for both treeviews.
    // Instance Variable
    ulong draggedhandle
    type tv_1 from treeview within w_treehop
    string dragicon = "Form!"
    boolean dragauto = true
    boolean disabledragdrop = false
    end type
    event begindrag;
    draggedhandle = handle
    end event
    event dragdrop;
    treeview tvSource
    treeviewitem ltvidropped, ltvidragged
    tvSource = source
    if draggedhandle > 0
      if handle <> draggedhandle or tvSource <> this then
        tvSource.GetItem( draggedhandle , ltvidragged )
        this.GetItem( handle , ltvidropped)
        this.Insertitemsort( handle, ltvidragged )
        tvSource.Deleteitem( draggedhandle )
        draggedhandle = 0
      end if
    end if
    end event
    type tv_2 from treeview within w_treehop
    string dragicon = "Form!"
    boolean dragauto = true
    boolean disabledragdrop = false
    end type
    event begindrag;
    draggedhandle = handle
    end event
    event dragdrop;
    treeview tvSource
    treeviewitem ltvidropped, ltvidragged
    tvSource = source
    if draggedhandle > 0
      if handle <> draggedhandle or tvSource <> this then
        tvSource.GetItem( draggedhandle , ltvidragged )
        this.GetItem( handle , ltvidropped)
        this.Insertitemsort( handle, ltvidragged )
        tvSource.Deleteitem( draggedhandle )
        draggedhandle = 0
      end if
    end if
    end event
    To carry over nested treeview items (children) you can use FindItem ( draggedhandle, navigationcode )
    navigationcode as per help:
         ChildTreeItem! The first child of itemhandle.
         NextTreeItem! The sibling after itemhandle. A sibling is an item at the same level with the same parent.
    HTH
    Lars

  • How to drag and drop button between two toolbar?

    Hi,everybody :)
    i hava a problem :
    if i have two toolbar in a frame , and there are some button in each, how can i use dnd package to drag and drop button between two toolbar,such as drag one button in a toolbar to the other toolbar ,i write some sample code ,but find some difficult to finish
    can anyone give me some example code?
    Thanks!

    hi:)
    i have done it ,but there is another problem ,after i finish drag the button and drop it into the toolbar,if my mouse across the dragged button ,it will change the color ,can i setup any mathod to disappear the side_effect?
    thank u
    click open to show the other frame
    and the code is as follows:
    import java.awt.*;
    import java.awt.datatransfer.*;
    import java.awt.dnd.*;
    import java.awt.event.*;
    import java.io.*;
    import javax.swing.*;
    public class buttondrag implements DragGestureListener, DragSourceListener,
    DropTargetListener, Transferable{
    static JFrame source = new JFrame("Source Frame");
    static JFrame target = new JFrame("Target Frame");
    static final DataFlavor[] supportedFlavors = { null };
    static {
    try {
         supportedFlavors[0] = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType);
    catch (Exception ex) {
         ex.printStackTrace();
    } Object object; // Transferable methods.
    public Object getTransferData(DataFlavor flavor) {
    if (flavor.isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType)) return object;
    else{
    return null;
    public DataFlavor[] getTransferDataFlavors() {
         return supportedFlavors;
    public boolean isDataFlavorSupported(DataFlavor flavor) {
         return flavor.isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType);
    } // DragGestureListener method.
    public void dragGestureRecognized(DragGestureEvent ev) {
    ev.startDrag(null, this, this);
    } // DragSourceListener methods.
    public void dragDropEnd(DragSourceDropEvent ev) { }
    public void dragEnter(DragSourceDragEvent ev) { }
    public void dragExit(DragSourceEvent ev) { }
    public void dragOver(DragSourceDragEvent ev) {
         object = ev.getSource();
    public void dropActionChanged(DragSourceDragEvent ev) { } // DropTargetListener methods.
    public void dragEnter(DropTargetDragEvent ev) { }
    public void dragExit(DropTargetEvent ev) { }
    public void dragOver(DropTargetDragEvent ev) { dropTargetDrag(ev); }
    public void dropActionChanged(DropTargetDragEvent ev) { dropTargetDrag(ev); }
    void dropTargetDrag(DropTargetDragEvent ev) { ev.acceptDrag(ev.getDropAction()); }
    public void drop(DropTargetDropEvent ev) {
         ev.acceptDrop(ev.getDropAction());
         try {
         Object target = ev.getSource();
         Object source = ev.getTransferable().getTransferData(supportedFlavors[0]);
         Component component = ((DragSourceContext) source).getComponent();
         Container oldContainer = component.getParent();
         Container container = (Container) ((DropTarget) target).getComponent();
         container.add(component);
         oldContainer.validate();
         oldContainer.repaint();
         container.validate();
         container.repaint();
         catch (Exception ex) {
              ex.printStackTrace();
              ev.dropComplete(true);
    public static void main(String[] arg) {
    JButton button = new JButton("Drag this button");
    JToolBar sbar = new JToolBar();
    JToolBar dbar = new JToolBar();
    JButton open_button = new JButton("Open");
    source.getContentPane().setLayout(null);
    source.setSize(new Dimension(400, 300));
    sbar.add(button);
    sbar.setBounds(new Rectangle(0, 0, 400, 31));
    sbar.add(open_button);
    open_button.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    target.setVisible(true);
    source.getContentPane() .add(sbar);
    target.getContentPane().setLayout(null);
    target.setSize(new Dimension(400, 300));
    target.getContentPane().add(dbar);
    dbar.setBounds(new Rectangle(0, 0, 400, 31));
    dbar.add(new JButton("button1"));
    buttondrag dndListener = new buttondrag();
    DragSource dragSource = new DragSource();
    DropTarget dropTarget1 = new DropTarget(sbar, DnDConstants.ACTION_MOVE, dndListener);
    DropTarget dropTarget2 = new DropTarget(dbar, DnDConstants.ACTION_MOVE, dndListener);
    DragGestureRecognizer dragRecognizer1 = dragSource.createDefaultDragGestureRecognizer(button, DnDConstants.ACTION_MOVE, dndListener);
    source.setBounds(0, 200, 200, 200);
    target.setVisible(false);
    target.setBounds(220, 200, 200, 200);
    source.show();
    }

  • How to drag and drop files between two JFileChooser

    Sir i want to drag and drop files between two JFileChooser i don't know how to do that. So is there any reference code for that so that i can able to do it. I have enabled setDragEnabled(true) for both the jfilechooser now i don't now how to drop files in them means drag file from one jfilechooser and drop it to another JFileChooser,.
    Plz help me this is the requirement in my project.

    Note: This thread was originally posted in the [New To Java|http://forums.sun.com/forum.jspa?forumID=54] forum, but moved to this forum for closer topic alignment.

  • How to drag and drop multi tabs to a new tab group?

    When I go to the new feature Tab Groups (shift+ctrl+E), I make a search then some tabs are highlighted but I would like to drag and drop to a new group the highlighted tabs all together not just one by one. Is it possible doing a multi-drag&drop with the CTRL+left mouse button?

    I see where you're going. I'm drawn to Thunderbird because it puts open emails in separate tabs, which makes finding a particular open message easier than searching the task bar for an open outlook message. I do see your point that tab happy programmers, probably too young to remember how cool we thought drag and drop was when it first came out, don't think much of it. As with a lot of software, each programmer has a very limited view of how it their program should be used vs how it is actually used in the wild.
    People work in different ways. When I schedule an appointment with a client, this is often preceded by a series of emails related to whatever the client wants to discuss. I drag and drop those messages into the appointment window so that on the date of the appointment, I have a nice neat summary of the issues right there in the appointment window. I could use workarounds (save email and then attach to the appointment), but that's like a trip back to Windows 3.0 and it's, if I'm not mistaken, 30+ years later. I guess I'll continue to use Tbird for email and outlook for calendar, not my preferred solution, I'd like to flip MS the bird and cut all ties to outlook, and was hoping Tbird was the solution. Not yet, and perhaps not ever, based on your thoughts.

  • How to Drag and Drop in between Stacks?

    I have a folder with various stacks and single images that I would like to sort manually. It seems impossible to drag and drop an image in between two stacks. It always ends up stacked with one or the other. I am being very careful to be sure that neither stack shows a border around it or is lighter than the other. But it makes no difference. Even if I expand both stacks, I can't drop an image in between. I have to completely UNSTACK the images, drag and then RE-STACK. Am I missing something??(running LR 2.4 on OSX 10.5.8)

    Yeah, it's a bit tricky, messing with stacks and drag-and-drop.
    Try going the other way round: drag and drop your stack (by selecting all images of the stack) instead of your single image, sometimes it helps (depending on the situation). The Remove from Stack command also helps to extract a single image from a stack without breaking and re-stacking.

Maybe you are looking for

  • Need to display chart in PowerView with data from YESTERDAY

    My apologies if this is a very basic question but I cannot, for the life of me, find a solution to this. I need to show ONLY yesterday's data on ONE of the charts I have on a PowerView dashboard. I also need to show Last WEEK's data (Today-7), last M

  • Dell ST2420L x 2 Plus 13" MBP

    Hello everyone, I'm thinking about buying a couple of the Dell ST2420L monitors and hooking them up to my 13" MBP (Mid-2010) to form a nice desk-top system.  I'm fairly new to this type of thing and don't know if I'll need more accessories or drivers

  • Http Post to XI Test Tool in Java?

    I have been able to use the HTML test tool shared on SDN for my scenarios to date, but I have been <u>also</u> trying to write an http post program in java.  For some reason the post never makes it to XI.  Does anyone have a sample they will share or

  • RMAN-08138: WARNING: archived log not deleted - must create more backups

    I ran: 1. CROSSCHECK ARCHIVELOG ALL 2. DELETE EXPIRED ARCHIVELOG ALL I am getting this error. I am trying to free my arciver after an ORA-00257 error. Can anyone help me out?

  • My ipod nano 5th generation is not working with windows 7

    Is there a driver needed to sync, I have not been able to find anything.