Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package swt;
- import java.io.BufferedOutputStream;
- import javafx.embed.swt.FXCanvas;
- import javafx.event.EventHandler;
- import javafx.scene.Scene;
- 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.Pane;
- import org.eclipse.swt.SWT;
- import org.eclipse.swt.layout.RowLayout;
- import org.eclipse.swt.widgets.Display;
- import org.eclipse.swt.widgets.Shell;
- public class SWTApp {
- static DataFormat refTrans = new DataFormat("MyDraggable");
- public static void main (String [] args) {
- Display display = new Display ();
- Shell shell = new Shell(display);
- final RowLayout layout = new RowLayout();
- shell.setLayout(layout);
- FXCanvas canvas = new FXCanvas(shell, SWT.FILL);
- final Pane pane = new Pane();
- pane.setOnDragDetected(new EventHandler<MouseEvent>() {
- @Override
- public void handle(MouseEvent event) {
- Dragboard db = pane.startDragAndDrop(TransferMode.COPY_OR_MOVE);
- ClipboardContent content = new ClipboardContent();
- BufferedOutputStream o = null;
- content.put(refTrans, "SomeText");
- db.setContent(content);
- event.consume();
- }
- });
- pane.setOnDragEntered(new EventHandler<DragEvent>() {
- @Override
- public void handle(DragEvent event) {
- System.out.println("DragEnter");
- for(DataFormat df : event.getDragboard().getContentTypes()){
- System.out.println(df.equals(refTrans));
- }
- }
- });
- Scene scene = new Scene(pane, 800, 600);
- canvas.setScene(scene);
- shell.open ();
- while (!shell.isDisposed ()) {
- if (!display.readAndDispatch ()) display.sleep ();
- }
- display.dispose ();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment