How to drag and drop nodes to tab between the components of the tab

I'm working on this tutorial example ( feature drag - move in the JavaFX Applications |) JavaFX tutorials and Documentation 2 ). Based on the tutorial I want to drag tabs between two tabs. So far, I have managed to create this code, but I need help to complete 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 correct way to insert the contents of the tab as an object? In the tutorial simple text is transferred. How do I change this line content.put(DataFormat.PLAIN_TEXT, tabPane); ?

And what is the right way to insert the tab after that 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 guess that this transfer is possible?

REF javafx 2 - How to drag and drop nodes between the components of the tab - stack overflow tab

I use a graphic (instead of text) for tabs and call setOnDragDetected on this chart. That way you know which tab is moved. There is no nice way to put the tab itself in the dragboard because it is not serializable (see https://javafx-jira.kenai.com/browse/RT-29082), so you'll want to probably just store currently slipped into a property tab.

Here's a quick example; It only add the tab at the end of the existing tabs in the pane has fallen. If you want to insert it in the location that is closest to the actual drop you probably browse the tabs and find details of chart of each tab, 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 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() {
      @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() {
      @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() {
      @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 ;
  }
}

Tags: Java

Similar Questions

  • With the help of Hewlett Packard Win 7 64 bit with Lightroom 5.7. I have read many explanations of how to drag and drop digital images in Lightroom - but I never got.  I need to know WHERE LTRM drop, HOW to find them and how to get them I

    I need to know EXACTLY how to drag and drop digital pictures into LTRM. WHERE to put them. HOW to find them. How to MOVE in the DEVELOPMENT MODULE.

    When you drag / drop photos, you actually perform a step to import, so it would be wise to figure out how to import your photos and all of the affected options. I agree with Jim Hess and al., drag / drop are an easy way to screw up your organization. Importing is a much more organized way to manage things. There are a lot of tutorial vid3os on import.

  • How to drag and drop the &lt; af:inputNumberSpinbox &gt; in Control Panel

    Hello

    I use jdev 11.1.1.4.0

    I need the component as < af:inputNumberSpinbox >. Create a data model and how to drag and drop into the inputNumberSpinbox of the data control.
    normally drog and drop the individual attribute as inputText box only. I want to < af:inputNumberSpinbox >.

    anythig want to change in the indicators of control view object itself. Help me.

    Kind regards
    Marilyn S.

    Published by: rami on June 22, 2011 16:45

    Hello

    Cannot drop you as an inputText and then change to the source for inputNumberSpinbox?

    Kind regards
    Stijn.

  • Why can I no longer drag and drop attachments in mail in the finder toolbar shortcut icons?

    Why, since I've upgraded to El Capitan, can I no longer drag and drop attachments of mail of the finder to my mail icon shortcut in the finder toolbar? When I do, I get a symbol indicating I can't drop the file there. It's a convenient shortcut for me.

    How did you get the icon in the tool bar of the Finder window? Using a type of extension?

  • Virtual PC for Windows 7 - How to drag-and - drop or transfer files

    I am trying to use Virtual PC for Windows 7 and be able to identify ways to transfer files from my host system in a virtual PC, I created.

    I was previously using Virtual PC (VPC) 2007 under Vista and am familiar with just the files dragging and droping to and from my host on the virtual computer system.

    I enabled the integration services and am unsure of what the user really wants that the VPC. that is he doesn't want configure me a Local user on the virtual machine or the host.

    I was able to connect to the virtual computer by using a local user on the computer virtual account, but for the life of me can not find out how to transfer files that I used to.

    To achieve what I need, I copy files to a shared location on my network as my PC and the virtual computer has access.

    Can anyone suggest how to get the 'integration' works correctly then drag and drop files between the Bureau of the VPC and host is possible.

    Thank you.

    Integration features allows the WVPC7 to share resources and readers. Open the virtual machine settings, and these options are available:

    1. Audio. Without integration, sounds played inside the virtual machine are emulated using a SoundBlaster 16 card. Audio output is fairly shrill and unpleasant to play using MP3s that imitated the sound card. With audio integration, sounds inside the VM are routed via Protocol Office remotely to your physical card. Audio output will be much better.
    2. Clipboard. Host OS and guest OS supported can share contents of the Clipboard.
    3. Printer. Applications within the virtual machine can print using your physical printer. This is useful if you have a parallel printer (LPT1). For USB printers, click on the "USB" menu on the toolbar of the virtual machine monitor, then attach your USB printer to your virtual machine.
    4. Smart cards. (I do not have any device of smart card, experts, please answer)
    5. Readers. Guest operating system can access and write files directly to your physical hard disks (or DVD or USB flash disk drive); is based on the physical disks, you have shared.

    For drag / drop, until today (2 July here) does not. I used to drag-and - drop files from my desktop windows vista to the desktop of the virtual machine (windows XP inside) you do, but now we can't. Another approach is to share your disks in has integration of options described above.

    After I shared my C: drive, a new 'shared' drive appeared in my virtual Windows XP [workstation], which is 'C on RYAN-PC' (the name may be different on your PC). Whenever I need to copy some files from my virtual computer on the desk of my windows 7, I just opened that shared drive, navigate to \\tsclient\C\Users\Ryan\Desktop\, copy the files and they come to my office windows 7.

    Personally I agree that even this method is simpler that the copy of the shared network files, drag-and - drop is much easier.

  • How to drag and drop an action on a workflow?

    How to pass the variable page ADF bind View object John says that

    You should also consider dragging operation executeWithParams on your workflow and of wiring to occur before your page instead of in the definition on the page itself - so it is more clear what is happening and is the approach recommended for 11 g applications. When drag-and you - drop operation, you can use the dialog box bind the parameter to your page flow - scope variable by providing the good EL there.

    How can I drag and drop the executeWithParams on a workflow method. I use 11.1.1.5.0 on LINUX?

    I assume that I need an action method in my flow of the page.

    I have the following action defined in my def of page file:

    < action IterBinding = "localizedCustomerHierarchyViewIterator".
    ID = "executeQueryWithParamsForLocalizedCustomerHierarchyView".
    InstanceName = "BusinessRulesAMDataControl.LocalizedCustomerHierarchyView"
    DataControl = "BusinessRulesAMDataControl" RequiresUpdateModel = "true".
    Action = "executeWithParams" >
    < NamedData NDName = "RootEntityId".
    NDValue = "#{pageFlowScope.recommendationRule.customerEntityId" "
    NDType = "java.lang.Long" NDOption = "3" / > "
    < NamedData NDName = 'language '.
    NDValue = "#{pageFlowScope.recommendationRule.language} '"
    NDType = "java.lang.String" NDOption = "3" / > "
    < / action >

    Just do drag and drop in the schema, see the demo here:
    http://blogs.Oracle.com/Shay/entry/passing_parameters_to_adf_appl

  • How to drag and drop photos to photos on memory stick

    seems I can is no longer just drag and drop photos on memory stick of my mac progesterone... .any suggestions?

    I don't know your problem makes the impression that I do not understand the relevance of female hormones.

  • Can someone please tell me how to drag and drop images of the pictures Mac (using Yosemite OS) program to 5.7 Lightroom?  Thank you.

    I just got a new computer and uses pictures instead of iPhoto for cataloging my images.  I would like to use Lightroom 5.7 for an editing tool, but I'm frustrated that I can't drag and drop the images I want to change?  Any ideas?

    Hi tamia82374570,

    Greetings.

    In my view, it is not possible that you are trying to import images from one application to another.

    • You will need to first export of photo images in a folder on the desktop or any other location
    • Then open LR, click Import and navigate to this location in the source Panel and import the images in LR.

    Concerning

    Rohit

  • How to drag and drop multiple movieclips at the same time

    Hello world

    I'm a new actonscript 3 and adobe flash CC user and I am building an application but I have been stuck for several days. I have looked everywhere and tried everything I could think of, but I can't yet find a solution to my problem that I thought were pretty basic.

    Basically, let's say I have a rectangle and a circle on the stage. Once I did of the movieclips and assigned an instance name to each of them, I want to be able to perform a drag and drop the Rectangle so that both the rectangle and the circle become movable at the same time.

    For now, I have a mouse down events listener associated with the instance of rectangle, a method startDrag assigned to the rectangle instance and another assigned to the circle. But in this configuration, when I click on and drag the rectangle, only the circle is mobile (only the last line in the code is taken into account).

    I don't know if what I'm trying to achieve is feasible, but any help will be greatly appreciated, thank you!

    The startDrag() method can only work for one object at a time, so in your case the Treaty the last of them, designated the task.  This approach is to temporarily to plant the two objects in a container and then drag the container.

    rectangle.addEventListener (MouseEvent.MOUSE_DOWN, fl_ClickToDrag);  When I click on the rectangle

    var dragMC:MovieClip = new MovieClip();
    addChild (dragMC);

    function fl_ClickToDrag(event:MouseEvent):void

    {
    dragMC.addChild (rectangle);        move objects in the container
    dragMC.addChild (circle);
    dragMC.startDrag ();
    }

    stage.addEventListener (MouseEvent.MOUSE_UP, fl_ReleaseToDrop); When I release the mouse button

    function fl_ReleaseToDrop(event:MouseEvent):void

    {
    dragMC.stopDrag ();
    Rectangle.x += dragMC.x;         Adjust the positions of the objects to their new location
    Rectangle.y += dragMC.y;
    Circle.x += dragMC.x;
    Circle.y += dragMC.y
    addChild (rectangle);                 move back to the scene objects
    addChild (circle);
    dragMC.x = dragMC.y = 0;       reset the benchmark for the dragMC
    }

    All this stuff of repositioning in the Drop function is necessary because when you drag the container, the positions of the content are still on their original coordinates inside the container.  So when you drop them they will resume their x / y positions in their new parent, meaning they go back where they were.  Reposition them where they have been trained to take into account the change in the position of the dragMC.

  • How can I allow a learner to examine one created Drag and Drop Quiz to show to the learner their incorrect answers or correct?

    Captivate 8: I created an assessment with two multiple choice question slides and 8 drag and drop question slides. After that the learner views their score, I wish they were able to examine all their answers to see where the mistakes were made. Currently, the revision quiz shows that their answers and the correct answers to multiple choice question slides. Ideally I'd like a review of question slides slide - déposer where the incorrect choices appear in red or something to that effect. I appreciate any insight and suggestions!

    Sorry, D & D are not a normal question slide and I can't recommend a feature request registration. I would really be able to choose if an interaction is reset or not, because this problem is not just for D & D but for all interactions of training as well.

  • How to drag and drop items in the Muse...

    Hello: Im attemping to create some drag and drop elements in muse. Can someone help me with this? Thank you

    You cannot create drag and then drop items using the off the features of the mailbox Muse. You may need to use some third-party JS library and integrate code using InsertHTML or HTML foroptions of Muse.

    Thank you

    Vikas

  • upgrade to connected hp eprint - can't drag and drop apps to organize them the way I did before!

    I upgraded to connected HP eprint today.  Now it wont let me not to the eprint site (and, Yes, I would not have gone back if something did not work to connected hp).

    I could drag and drop placement of my apps to have as I would like on the touchscreen to eprint printer.   However, I can't do drag or drop whatever it is connected HP, and I see no help on the management of the investment of the apps on your printer.

    How is that possible?  It was easy before - printer just drag-and - drop and website updated.  I have an officejet 7610.

    Thanks in advance!

    Thanks for trying, but your answer is incorrect, according to an email I received today from HP connected:

    "I have reviewed your email. I understand you have questions related to the reorganization of the order of apps on the printer. I know this can be frustrating, and I want you to know you are certainly valuable for us and I want to do everything possible to ensure your complete satisfaction. The following information should provide the answers you need:

    (1) Unfortunately when HP has launched the new website (www.hpconnected.com) they do not include a method to rearrange applications on the printer. They can include this feature in a future update, but as this time it is not available.

    (2) If you did upgrade to connected HP eprintcenter, you do have the option of return. EPrintCenter is being be eliminated and retune to the old site unfortunately is not possible. »

    I hope that < < S-O-O-N > > HP fixed this new Web site - it's crazy take-out all controls like that from their customers and not embellish their or at least let them be.

    I can take this OJ 7610 back for a new brother 11 x 17 all-in-in-one - they look nice )

  • Use drag and drop to sort data in the report

    Hello!

    I found a good description to sort the data in a tabular by drag and drop form.

    Hello

    Here's the example query:

    SELECT
      empno,
      ename,
      job,
      mgr,
      hiredate,
      sal,
      comm,
      deptno,
      APEX_ITEM.HIDDEN(1, rowid) AS sort_col
    FROM emp
    ORDER BY display_seq
    

    Change the SORT_COL attributes:

    The value column report Standard display type.

    Add in the link text column

    #SORT_COL#
    

    Replace the URL and URL target #.

    When you submit page you get rowid in APEX_APPLICATION. Table G_F01.

    Kind regards
    Jari

  • trackpad no reaction on drag and drop, when I press on the very short?

    Hello

    I wonder if I have to go to apple genius bar like my trackpad (retina mb 12 ")

    does not react when I press on and move an item, press only when a fractons of a second.

    This is how different my mb air

    right?

    Could not edit my previous post:

    It does not react when I press on and want to hold/move an element, only when I press on a fraction of a second, it works.

    When I hold down, it shows me the image of overview of the issue, even while pressing the space bar.

    It seems very delicate, because I'm used to drag and move an item by clicking / pressing more time to activate items and then drag them to another place,

    by moving my finger on the trackpad.

    This is what apple has changed or is not working properly my trackpad?

    Thank you

  • How to drag and drop multiple objects in a mask?

    nightvision.jpg

    I worked on a flash Simulator to show what our night vision product would look like in the dark.  I managed in the implementation with the following code below.  However, I can't add a picture "crosshairs" (or symbol) to the movable mask to make it work.  Can someone help me with the code?  I looked for hours on the internet and I can't make it work.  I'm new to Flash, but begins to learn as much as I can.

    ActionScript 3:

    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 (such as enterframe) and update the position of the reticle to match the position of mask_mc.

    mg_nv. Mask = mask_mc;

    mask_mc.buttonMode = true;

    for example, 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 that they both have the same reg points (as the Center)

    reticle_mc.y = mask_mc.y;

    }

Maybe you are looking for