JavaFX drag events destroyed by window resize

Hello,
I've been having great success developing a drag-drop component for a JavaFX app, but I've run into an issue that has me completely stumped.
Specifically, I create a component that can be dragged around inside an anchor pane.  That anchorpane is nested in a split pane, which is nested in another anchor pane (the control's root element).
The issue can be described this way:
Case #1:  If I start the application as a small window, I can reposition the control by dragging it around the screen as I please.
Case #2: If I start the application and maximize the window, again, I can drag the control around the screen as I please.
Case #3: If I start the application, drag the control around a bit, then resize the window, the drag event handling breaks as follows:
1.  The control drag events will fire normally only within the bounds of the anchor pane's previous size.
2.  The mouse cursor's drag icon changes as I pass in or out of those bounds
I'm absolutely certain the anchorpane is resizing to match the parent window, otherwise Case #2 would not succeed.  I'm at a complete loss as to determine why the drag events don't fire within the bounds of the resized window after they've been fired within the bounds of it's previous size.
Understand the mechanism I'm using to establish the drag handling:  Once the controller is instantiated and added to the scene, an event listener on the class's parentProperty fires to attach the drag event handling to the parent node.
Previously, I was setting / clearing the drag handling on the parent node in the drag detection / drag dropped event handlers.  I had suspected that adding / removing drag events was causing the trouble and opted for this solution to ensure that the same event instance
was being used each time.  Both methods have had the same result.
If you want to see the UI in action, here's a youtube link (it does not demonstrate the problem I'm having):
http://youtu.be/FJWRFN8xHFY
Here's the code that I'm using, redacted for clarity:
public class FileSystemNode extends AnchorPane {
    @FXML private AnchorPane fs_node_title;
    private FileSystemType mFsType;
    private Point2D mDragPoint;
    private EventHandler <MouseEvent> mNodeDragDetected;
    public FileSystemNode() {
        loadFxml();
        setId(mFsType.toString() + Double.toString(Math.random()));
    private void loadFxml() {
        FXMLLoader fxmlLoader = new FXMLLoader(
                getClass().getResource("/FileSystemNode.fxml"));
        fxmlLoader.setRoot(this);
        fxmlLoader.setController(this);
        try {
            fxmlLoader.load();
             parentProperty().addListener(new ChangeListener() {
                    @Override
                    public void changed(ObservableValue observable,
                            Object oldValue, Object newValue) {   
                        buildNodeDragHandlers();   
                        fs_node_title.setOnDragDetected(mNodeDragDetected);       
        } catch (IOException exception) {
            throw new RuntimeException(exception);
    public void relocateToPoint (Point2D p) {
        Point2D p2 = getParent().sceneToLocal(p);
        relocate (
                (int) (p2.getX() - mDragPoint.getX()),
                (int) (p2.getY() - mDragPoint.getY())
    public void buildNodeDragHandlers() {
        getParent().setOnDragOver(new EventHandler <DragEvent>() {
            //dragover to handle node dragging in the right pane view
            @Override
            public void handle(DragEvent event) {       
                event.acceptTransferModes(TransferMode.ANY);
                relocateToPoint(new Point2D( event.getSceneX(), event.getSceneY()));
                event.consume();
        getParent().setOnDragDropped(new EventHandler <DragEvent> () {
            @Override
            public void handle(DragEvent event) {
                event.setDropCompleted(true);
                event.consume();
        //drag detection for node dragging
        mNodeDragDetected = new EventHandler <MouseEvent> () {
            @Override
            public void handle(MouseEvent event) {
                mDragPoint = new Point2D(event.getX(), event.getY());
                        relocateToPoint(new Point2D(event.getSceneX(), event.getSceneY()));
                        ClipboardContent content = new ClipboardContent();
                        content.putString("node_drag");
                        startDragAndDrop (TransferMode.ANY).setContent(content);               
                        event.consume();                   

Ok, I managed to reduce this even further to a single class that generates the entire application and drag events all at once.
Copy / paste this into a new javaFX application to test it.  The case tests are:
1.  drag/drop the "drag me!" label in the window's starting size
2.  drag/drop the "drag me!" label only after resizing the window
3.  Combine cases #1 and #2, dragging and dropping, resizing, then dragging and dropping again.
In case 3, what happens for me is that the label cannot be dragged beyond the window's original bounds even though it's been resized to a larger size.
If anyone with a better clue than I could try it and give me some thoughts, I'd certainly be appreciative.
Thanks.
import javafx.geometry.Point2D;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.DragEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import javafx.application.Application;
import javafx.event.EventHandler;
public class Main extends Application {
    private AnchorPane node_root;
    private BorderPane mRoot;
    @Override
    public void start(Stage primaryStage) {
        try {
            node_root = new AnchorPane();
            mRoot = new BorderPane();
            Scene scene = new Scene(mRoot,400,400);
            primaryStage.setScene(scene);
            primaryStage.show();
        } catch(Exception e) {
            e.printStackTrace();
        addFileSystemNode ();
        mRoot.setOnDragDone (new EventHandler <DragEvent>() {
            @Override
            public void handle(DragEvent event) {
System.out.println ("Drag done");
                event.consume();
    public static void main(String[] args) {
        launch(args);
    public final void addFileSystemNode () {
        Label node_title = new Label();
        node_title.setText("drag me!");
        node_root.getChildren().add (node_title);
        mRoot.getChildren().add (node_root);
        buildNodeDragHandlers();    
        node_root.setLayoutX(100.0);
        node_root.setLayoutY(100.0);
    public void relocateToPoint (Point2D p) {
        Point2D p2 = mRoot.sceneToLocal(p);
        node_root.relocate (
                (int) (p2.getX()),
                (int) (p2.getY())
    public void buildNodeDragHandlers() {
        mRoot.setOnDragOver(new EventHandler <DragEvent>() {
            //dragover to handle node dragging in the right pane view
            @Override
            public void handle(DragEvent event) {
                System.out.println("parent node drag over" + " "  + ((Pane) event.getSource()).getId());
                event.acceptTransferModes(TransferMode.ANY);
                relocateToPoint(new Point2D( event.getSceneX(), event.getSceneY()));
                event.consume();
        mRoot.setOnDragDropped(new EventHandler <DragEvent> () {
            @Override
            public void handle(DragEvent event) {
                System.out.println("node drag dropped");            
                event.setDropCompleted(true);
                event.consume();
        //drag detection for node dragging
        node_root.setOnDragDetected( new EventHandler <MouseEvent> () {
            @Override
            public void handle(MouseEvent event) {
                System.out.println("Drag detected");            
                //begin drag ops
                relocateToPoint(new Point2D(event.getSceneX(), event.getSceneY()));
                ClipboardContent content = new ClipboardContent();
                content.putString("node_drag");
                node_root.startDragAndDrop (TransferMode.ANY).setContent(content);            
                event.consume();                

Similar Messages

  • Node Container that does not resize with Window Resize Event

    Hello,
    I'm not new to Java but I am new to JavaFX.
    I plan to have a container/Canvas with multiple shapes (Lines, Text, Rectangle etc) in it. This Container can be X times in the Szene with different Text Shapes. I need to Zoom and Pan (maybe rotation) the whole Szene and the Containers/Canvas.
    So I was playing around with that but I have two issues.
    1) all Canvas classes that I found (like Pane for example) do resize with the main window resize event. The content of the canvas isn't centered any more.
    2) I added a couple of Rectangles to the canvas and both the rectangles and the canvas have a mouse listener which will rotate the item/canvas. Problem is, that even if I click the rectangle also the underlaying canvas is rotated...I think I need some kind of Z-Info to find out what was clicked.
    Here is the little example program, it makes no produktiv sense but it demonstrates my problem.
    Does anybody has a tip what canvas class would fit and does not resize with the main window and how to figure out what was clicked?
    public class Test extends Application
         Scene mainScene;
         Group root;
         public static void main(String[] args)
            launch(args);
        @Override
        public void init()
            root = new Group();
            int x = 0;
            int y = -100;
            for(int i = 0; i < 5; i++)
                 x = 0;
                 y = y + 100;
                 for (int j = 0; j < 5; j++)
                      final Rectangle rect = new Rectangle(x, y, 30 , 30);
                       final RotateTransition rotateTransition = RotateTransitionBuilder.create()
                             .node(rect)
                             .duration(Duration.seconds(4))
                             .fromAngle(0)
                             .toAngle(720)
                             .cycleCount(Timeline.INDEFINITE)
                             .autoReverse(true)
                             .build();
                     rect.setOnMouseClicked(new EventHandler<MouseEvent>()
                          public void handle(MouseEvent me)
                               if(rotateTransition.getStatus().equals(Animation.Status.RUNNING))
                                    rotateTransition.setToAngle(0);
                                    rotateTransition.stop();
                                    rect.setFill(Color.BLACK);
                                    rect.setScaleX(1.0);
                                    rect.setScaleY(1.0);
                               else
                                    rect.setFill(Color.AQUAMARINE);
                                    rect.setScaleX(2.0);
                                    rect.setScaleY(2.0);
                                    rotateTransition.play();
                      root.getChildren().add(rect);
                      x = x + 100;
        public void start(Stage primaryStage)
             final Pane pane = new Pane();
             pane.setStyle("-fx-background-color: #CCFF99");
             pane.setOnScroll(new EventHandler<ScrollEvent>()
                   @Override
                   public void handle(ScrollEvent se)
                        if(se.getDeltaY() > 0)
                             pane.setScaleX(pane.getScaleX() + 0.01);
                             pane.setScaleY(pane.getScaleY() + 0.01);
                        else
                             pane.setScaleX(pane.getScaleX() - 0.01);
                             pane.setScaleY(pane.getScaleY() - 0.01);
             pane.getChildren().addAll(root);
             pane.setOnMouseClicked(new EventHandler<MouseEvent>(){
                   @Override
                   public void handle(MouseEvent event)
                        System.out.println(event.getButton());
                        if(event.getButton().equals(MouseButton.PRIMARY))
                             System.out.println("primary button");
                             final RotateTransition rotateTransition2 = RotateTransitionBuilder.create()
                                  .node(pane)
                                  .duration(Duration.seconds(10))
                                  .fromAngle(0)
                                  .toAngle(360)
                                  .cycleCount(Timeline.INDEFINITE)
                                  .autoReverse(false)
                                  .build();
                             rotateTransition2.play();
             mainScene = new Scene(pane, 400, 400);
             primaryStage.setScene(mainScene);
            primaryStage.show();
    }Edited by: 953596 on 19.08.2012 12:03

    To answer my own Question, it depends how you add childs.
    It seems that the "master Container", the one added to the Scene will allways resize with the window. To avoid that you can add a container to the "master Container" and tell it to be
    pane.setPrefSize(<child>.getWidth(), <child>.getHeight());
    pane.setMaxSize(<child>.getWidth(), <child>.getHeight());
    root.getChildren().add(pane);and it will stay the size even if the window is resized.
    Here is the modified code. Zooming and panning is working, zomming to window size is not right now. I'll work on that.
    import javafx.animation.Animation;
    import javafx.animation.ParallelTransition;
    import javafx.animation.ParallelTransitionBuilder;
    import javafx.animation.RotateTransition;
    import javafx.animation.RotateTransitionBuilder;
    import javafx.animation.ScaleTransitionBuilder;
    import javafx.animation.Timeline;
    import javafx.animation.TranslateTransitionBuilder;
    import javafx.application.Application;
    import javafx.event.EventHandler;
    import javafx.geometry.Point2D;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.input.MouseButton;
    import javafx.scene.input.MouseEvent;
    import javafx.scene.input.ScrollEvent;
    import javafx.scene.layout.Pane;
    import javafx.scene.paint.Color;
    import javafx.scene.shape.Rectangle;
    import javafx.stage.Stage;
    import javafx.util.Duration;
    public class Test extends Application
         Stage primStage;
        Scene mainScene;
         Group root;
         Pane masterPane;
         Point2D dragAnchor;
         double initX;
        double initY;
         public static void main(String[] args)
            launch(args);
        @Override
        public void init()
            root = new Group();
            final Pane pane = new Pane();
            pane.setStyle("-fx-background-color: #CCFF99");
            pane.setOnScroll(new EventHandler<ScrollEvent>()
                @Override
                public void handle(ScrollEvent se)
                    if(se.getDeltaY() > 0)
                        pane.setScaleX(pane.getScaleX() + pane.getScaleX()/15);
                        pane.setScaleY(pane.getScaleY() + pane.getScaleY()/15);
                        System.out.println(pane.getScaleX() + " " + pane.getScaleY());
                    else
                        pane.setScaleX(pane.getScaleX() - pane.getScaleX()/15);
                        pane.setScaleY(pane.getScaleY() - pane.getScaleY()/15);
                        System.out.println(pane.getScaleX() + " " + pane.getScaleY());
            pane.setOnMousePressed(new EventHandler<MouseEvent>()
                public void handle(MouseEvent me)
                    initX = pane.getTranslateX();
                    initY = pane.getTranslateY();
                    dragAnchor = new Point2D(me.getSceneX(), me.getSceneY());
            pane.setOnMouseDragged(new EventHandler<MouseEvent>()
                public void handle(MouseEvent me) {
                    double dragX = me.getSceneX() - dragAnchor.getX();
                    double dragY = me.getSceneY() - dragAnchor.getY();
                    //calculate new position of the pane
                    double newXPosition = initX + dragX;
                    double newYPosition = initY + dragY;
                    //if new position do not exceeds borders of the rectangle, translate to this position
                    pane.setTranslateX(newXPosition);
                    pane.setTranslateY(newYPosition);
            int x = 0;
            int y = -100;
            for(int i = 0; i < 5; i++)
                 x = 0;
                 y = y + 100;
                 for (int j = 0; j < 5; j++)
                      final Rectangle rect = new Rectangle(x, y, 30 , 30);
                       final RotateTransition rotateTransition = RotateTransitionBuilder.create()
                             .node(rect)
                             .duration(Duration.seconds(4))
                             .fromAngle(0)
                             .toAngle(720)
                             .cycleCount(Timeline.INDEFINITE)
                             .autoReverse(true)
                             .build();
                     rect.setOnMouseClicked(new EventHandler<MouseEvent>()
                          public void handle(MouseEvent me)
                               if(rotateTransition.getStatus().equals(Animation.Status.RUNNING))
                                    rotateTransition.setToAngle(0);
                                    rotateTransition.stop();
                                    rect.setFill(Color.BLACK);
                                    rect.setScaleX(1.0);
                                    rect.setScaleY(1.0);
                               else
                                    rect.setFill(Color.AQUAMARINE);
                                    rect.setScaleX(2.0);
                                    rect.setScaleY(2.0);
                                    rotateTransition.play();
                      pane.getChildren().add(rect);
                      x = x + 100;
            pane.autosize();
            pane.setPrefSize(pane.getWidth(), pane.getHeight());
            pane.setMaxSize(pane.getWidth(), pane.getHeight());
            root.getChildren().add(pane);
            masterPane = new Pane();
            masterPane.getChildren().add(root);
            masterPane.setStyle("-fx-background-color: #AABBCC");
            masterPane.setOnMousePressed(new EventHandler<MouseEvent>()
               public void handle(MouseEvent me)
                   System.out.println(me.getButton());
                   if((MouseButton.MIDDLE).equals(me.getButton()))
                       double screenWidth  = masterPane.getWidth();
                       double screenHeight = masterPane.getHeight();
                       System.out.println("screenWidth  " + screenWidth);
                       System.out.println("screenHeight " + screenHeight);
                       System.out.println(screenHeight);
                       double scaleXIs     = pane.getScaleX();
                       double scaleYIs     = pane.getScaleY();
                       double paneWidth    = pane.getWidth()  * scaleXIs;
                       double paneHeight   = pane.getHeight() * scaleYIs;
                       double screenCalc    = screenWidth > screenHeight ? screenHeight : screenWidth;
                       double scaleOperator = screenCalc  / paneWidth;
                       double moveToX       = (screenWidth/2)  - (paneWidth/2);
                       double moveToY       = (screenHeight/2) - (paneHeight/2);
                       System.out.println("movetoX :" + moveToX);
                       System.out.println("movetoY :" + moveToY);
                       //double scaleYTo = screenHeight / paneHeight;
                       ParallelTransition parallelTransition = ParallelTransitionBuilder.create()
                               .node(pane)
                               .children(
                                   TranslateTransitionBuilder.create()
                                       .duration(Duration.seconds(2))
                                       .toX(moveToX)
                                       .toY(moveToY)
                                       .build()
                                   ScaleTransitionBuilder.create()
                                       .duration(Duration.seconds(2))
                                       .toX(scaleOperator)
                                       .toY(scaleOperator)
                                       .build()
                      .build();
                       parallelTransition.play();
        public void start(Stage primaryStage)
             primStage = primaryStage;
            mainScene = new Scene(masterPane, 430, 430);
             primaryStage.setScene(mainScene);
            primaryStage.show();
    }

  • Catch only the last resize event of a window

    Hi
    I've gone through the forums but can't find a solution.
    Only for one of my JFrames I have to watch for component resize and trigger an action after mouse has been released.
    I'm listening for componentResize but get all of them during dragging. As it is only for one window I cannot disable the dynamic layout property. Next I thought to catch the mouse release event and see that resize has been done before.
    But I'm not able to get this event. Toolkit.addAWTEventListener() is not informed about this mouse event.
    Any idea?
    Thanks in advance
    Wolfgang R.

    Ok, the example below produces only one final event on Windows but multiple events on Linux (jdk1.6.0)
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Toolkit;
    import java.awt.event.ComponentAdapter;
    import java.awt.event.ComponentEvent;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class Sample {
         private static int count = 0;
         public static void main(String[] args) {
              JFrame frame = new JFrame();
    //          System.out.println("dynamic layout: "
    //               + Toolkit.getDefaultToolkit().isDynamicLayoutActive());
    //          Toolkit.getDefaultToolkit().isDynamicLayoutActive();
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              JPanel panel = new JPanel();
              panel.setPreferredSize(new Dimension(100, 100));
              panel.setBackground(Color.BLUE);
              frame.add(panel);
              frame.addComponentListener(new ComponentAdapter() {
                   public void componentResized(ComponentEvent e) {
                        System.out.println("count: " + count++);
              frame.pack();
              frame.setVisible(true);
    }

  • Window Resizing event

    Is there any way to detect a window resizing event? When I grad the corner of a JFrame, I'd like to be able to tell that it is being resized. If anyone konw a way of doing this, please let me know.
    Alan

    You could have your window implement the ComponentListener interface. There is a method that gets called when the component's size changes.
    -S-

  • Browser window resize event

    Newbie question - sorry. How do I capture the browser window
    resize event?
    I've tried variations on this code:-
    <mx:Script>
    <![CDATA[
    import flash.events.Event;
    function mylisten():void { trace('mylisten');
    this.stage.addEventListener(Event.RESIZE,resizefn);
    function resizefn():void {
    trace('resize!');
    ]]>
    </mx:Script>

    Hi brutfood,
    you can add a handler to the resize event of the application
    as an attribute of the Application tag.
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute" resize="resizeHandler()">
    Then add the handler ("t" is TextArea):
    private function resizeHandler():void {
    t.text = stage.width + " - " + stage.height;
    t.text += "\n" + stage.stageWidth + " - " +
    stage.stageHeight;
    Note the difference between the width/height and
    stageWidth/stageHeight properties: the first couple returns the
    actual stage dimension while the second returns the visible area of
    the stage.
    regards,
    Christophe

  • Drag event handling in JFXPanel has performance implications with expensive event handlers

    We have a drag event handler that is a little expensive, takes something like 20ms. The respective code must be run in a synchronous manner however.
    That is no problem in a pure JavaFX environment, as less drag events are created when CPU load is high.
    However, when embedded into Swing using JFXPanel this adaptation doesn't kick in, lots of drag events are created and the application becomes sluggish.
    Is there a way to mimic what JavaFX does in the JFXPanel scenario?
    The code below is a self-contained example that demonstrates what I'm describing.
    Some results I had:
    -eventHandlerSleep=5 -noswing --> 128 drag events
    -eventHandlerSleep=30 -noswing --> 46 drag events
    -eventHandlerSleep=5  --> 136 drag events
    -eventHandlerSleep=30  --> 135 drag events
    {code}import java.util.Arrays;
    import javax.swing.*;
    import com.sun.glass.ui.Robot;
    import javafx.application.Application;
    import javafx.application.Platform;
    import javafx.embed.swing.JFXPanel;
    import javafx.event.EventHandler;
    import javafx.scene.Scene;
    import javafx.scene.input.MouseEvent;
    import javafx.scene.layout.BorderPane;
    import javafx.stage.Stage;
    public class DragHandlingTester {
        private static long EVENT_HANDLER_SLEEP = 30;
        public static void main(String[] args) {
            for (String arg : args) {
                if (arg.startsWith("-eventHandlerSleep=")) {
                    EVENT_HANDLER_SLEEP = Long.parseLong(arg.split("=")[1]);
            if (Arrays.asList(args).contains("-noswing")) {
                Application.launch(JavaFXDragHandlingTestApp.class, args);
            } else {
                new SwingDragHandlingTestApp();
        static class SwingDragHandlingTestApp {
            SwingDragHandlingTestApp() {
                JFrame frame = new JFrame();
                final JFXPanel fxMainPanel = new JFXPanel();
                Platform.runLater(new Runnable() {
                    @Override
                    public void run() {
                        DragTestScene dragTestScene = new DragTestScene();
                        fxMainPanel.setScene(dragTestScene.createScene());
                frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
                frame.getContentPane().add(fxMainPanel);
                frame.setSize(800, 600);
                frame.setVisible(true);
        public static class JavaFXDragHandlingTestApp extends Application {
            @Override
            public void start(Stage primaryStage) {
                primaryStage.setWidth(800);
                primaryStage.setHeight(600);
                primaryStage.setX(0.0);
                primaryStage.setY(0.0);
                DragTestScene dragTestScene = new DragTestScene();
                primaryStage.setScene(dragTestScene.createScene());
                primaryStage.show();
        static class DragTestScene {
            private int drags = 0;
            public Scene createScene() {
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            // after 1 second drag mouse across window
                            Thread.sleep(1000);
                            Robot robot = com.sun.glass.ui.Application.GetApplication().createRobot();
                            robot.mouseMove(50, 50);
                            robot.mousePress(1);
                            for (int i = 20; i &lt; 700; i = i + 5) {
                                robot.mouseMove(i, 50);
                                Thread.sleep(10);
                            robot.mouseRelease(1);
                        } catch (Exception e) {
                            e.printStackTrace();
                }).start();
                BorderPane borderPane = new BorderPane();
                borderPane.setOnMouseDragged(new EventHandler() {
                    @Override
                    public void handle(MouseEvent mouseEvent) {
                        drags++;
                        try {
                            Thread.sleep(EVENT_HANDLER_SLEEP);
                        } catch (InterruptedException ignored) {
                        System.out.println("Number of drag events: " + drags);
                return new Scene(borderPane);
    {code}

    Ok, I expected something like this to be the reason. We'll probably have to live with it.
    My workaround right now is to use background tasks with an executor that has a single element queue handling the events in order, but rejecting any additional events as long as there is a queued event.
    Still not the same performance as in JavaFX, but at least it's usable now.

  • Crashes on window resize

    I am a loyal user of logic for 8 years now. yes I'm posting about an issue where logic crashes (as in: freezes for 30 seconds then closes even if other apps are reWired to it)
    It does this SOMETIMES, when resizing any window in logic..
    it says: UNEFINED RECURSION ERROR and then you know you'll be rebooting your mac g5 (tested on g4 too)
    I sit here thinking of ten years of buying updates.
    and by PURE LUCK alone, I buy every update hoping that certain issues will be fixed. Most are not.
    On a mac there are two ways a window can be act when being resized:
    1 - as you drag the re-sizer corner of the window, you see only a dotted outline of the window, then when you let go, the window resizes.
    2 - as you drag, the entire contents of the window moves as you drag.
    #2 causes crashes. #1 is fast and quick.
    Mr. Moderator, you can delete this post as expected. But you do know as well as I do, these guys never do a user request.
    I mean my $200 alone is enough to pay one developer to fix things like this.
    Nevermind $200 from 2 million people!
    What are you doing with your user requests and your users money?

    Might try removing your media files associated with the project... put them in another folder, or disconnect the fw drive that holds them...?
    Do other project files do the same or just this one?
    Jerry

  • Default implementation of mouse drag event?

    Is there any Default implementation of mouse drag event?
    Say if the developer does not override and implement mouse drag event, still when the frame is dragged, the frame gets repainted itself in the new position. It indicates some default implementation of mouse drag event, but am unable to find out where it has been implemented.
    Why bother when everything works fine? I have a requirement to move my non-modal dialog when the frame is being dragged to another location. I tried adding mousemotionlistener to the frame, to the panel inside a frame, but the event does not reach my custom implementation of mousedrag event.
    Any clues?

    Moving the frame is a different listener: ComponentListener; add one to the frame. The frame's window decorations are OS territory, so I'm not sure if there's system dependence. I seem to vaguely remember some systems sending an event only after done moving, while others send the event as the frame moves.

  • Terminal window resizes when opening new tab with cmd-'t'

    The simplest way to re-create this issue is as follows:
    -open new Terminal window (def 80x24)
    -resize the Terminal window by dragging the lower right corner (125x32)
    -cmd-'t'
    -resize the Terminal window (80x24)
    -cmd-'t'
    After the final command the Terminal window resizes itself back to 125x32.
    This only appears to increase the size of the Terminal window; this does not occur when shrinking it. I'd really like to be able to disable this resizing "feature".
    Thank you in advance.

    tpol_ wrote:
    This is on Snow Leopard 10.6.2. I didn't recall having this issue in 10.5 either so I'm glad to hear I'm not losing my mind.
    I'm not running 10.6.x yet, so someone else will have to step in.
    You might want to post your observation as a bug report:
    http://www.apple.com/feedback/macosx.html

  • Mouse dragged event with unexpected coordinates

    I am dragging the mouse on a half circle from the middle left to the top middle. This results in mouse events with the coordinates form (10,90) ->(100,10)
    Letting the mouse go and then dragging it further to the left, the coordinates in the of the event are similar than the starting point of the first mouse drag event.
    Can anyone shed some light on this peculiar behavior?

    First of, I have to apologize for the example not being as minimalistic as it might be, but on the plus side, I know now why this happens, I just don't know how to work around it.
    * To change this license header, choose License Headers in Project Properties.
    * To change this template file, choose Tools | Templates
    * and open the template in the editor.
    package javafxtest;
    import java.util.ArrayList;
    import javafx.application.Application;
    import javafx.beans.property.DoubleProperty;
    import javafx.beans.property.SimpleDoubleProperty;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.geometry.Dimension2D;
    import javafx.geometry.Point2D;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.control.Label;
    import javafx.scene.input.MouseEvent;
    import javafx.scene.layout.StackPane;
    import javafx.scene.paint.Color;
    import javafx.scene.shape.Circle;
    import javafx.scene.shape.Polygon;
    import javafx.scene.shape.Rectangle;
    import javafx.scene.shape.Shape;
    import javafx.scene.transform.Rotate;
    import javafx.stage.Stage;
    * @author andi
    public class HandleRotation extends Application {
        private DoubleProperty currentRotation;
        private ArrayList<Double> angles;
        @Override
        public void start(Stage primaryStage) {
            currentRotation = new SimpleDoubleProperty(this, "currentRotation", 10);
            SteeringWheelGroup background = new SteeringWheelGroup(200);
            background.setManaged(false);
            Group g = new Group(background);
            final Point2D centerPoint = new Point2D(100, 100);
            angles = new ArrayList<>(3);
            angles.add(190.0);
            angles.add(270.0);
            angles.add(350.0);
            double step = (180.0 - 2 * currentRotation.doubleValue()) / (angles.size() - 1);
            int radius = 100;
            final int yTranslation = 15; // might be due to the labels
            Polygon handle = createHandle(centerPoint, radius, yTranslation);
            g.getChildren().add(handle);
            StackPane root = new StackPane();
            Scene scene = new Scene(g, 300, 250);
            primaryStage.setTitle("Handle Rotation!");
            primaryStage.setScene(scene);
            primaryStage.show();
         * Calculate the base point for the label. This is the point on the arc, matching the angle.
         * @param center point of the circle
         * @param radius radius of the circle
         * @param angle in degree in [0,180]
         * @return Point on the circle
        Point2D calculateBasePoint(Point2D center, double radius,
                double angle) {
            float newX = (float) (center.getX() + radius * Math.cos(Math.toRadians(angle)));
            float newY = (float) (center.getY() + radius * Math.sin(Math.toRadians(angle)));
            return new Point2D(newX, newY);
         * Create the polygon that represents the handle
         * @param centerPoint
         * @param radius
         * @return
        private Polygon createHandle(final Point2D centerPoint, int radius, final int yTranslation) {
            double baseAngle = 180;
            Point2D p1 = calculateBasePoint(centerPoint, radius, baseAngle - 5);
            Point2D p2 = calculateBasePoint(centerPoint, radius, baseAngle + 2);
            Point2D p3 = calculateBasePoint(centerPoint, radius*0.65, baseAngle + 2);
            Point2D p4 = calculateBasePoint(centerPoint, radius*0.65, baseAngle - 7);
            double[] points = {p1.getX(), p1.getY(), p2.getX(), p2.getY(), p3.getX(), p3.getY(), p4.getX(), p4.getY()};
                      Polygon polygon = new Polygon(points);
    //        polygon.setOpacity(0);
            polygon.setTranslateY(-yTranslation);
            final Rotate rotationTransform = new Rotate(currentRotation.doubleValue(), centerPoint.getX(), centerPoint.getY());
            polygon.getTransforms().add(rotationTransform);
            polygon.setOnMouseDragged(new EventHandler<MouseEvent>() {
                @Override
                public void handle(MouseEvent event) {
                    if (event.getY() < centerPoint.getY()) {
    System.out.println("Event: "+event);                   
                                                       Point2D point = new Point2D((float)event.getX(), (float)event.getY());
                        double newAngle = angleBetween2Lines(centerPoint, point);
                        if (newAngle < 0) {
                            newAngle = (90 + newAngle)+ 90;
    System.out.println("Set angle on mouse drag: "+newAngle);
                        if (newAngle < 10) {
                            newAngle = 10;
                        if (newAngle > 170) {
                            newAngle = 170;
                        currentRotation.set(newAngle);
            polygon.setOnMouseReleased(new EventHandler<MouseEvent>() {
                @Override
                public void handle(MouseEvent event) {
                    snapToNearestAngle();
                    rotationTransform.setAngle(currentRotation.doubleValue());
            return polygon;
         * Snap to the correct angle. Correct angle is angle belonging to the nearest label.
        void snapToNearestAngle() {
            double currentAngle = currentRotation.doubleValue() + 180;
            double currentMin = 360;
            int minIndex = 0;
    System.out.println("Current rotation is "+currentAngle);
            for (int i = 0; i < angles.size(); i++) {
                double angle = angles.get(i);
                double diff = Math.abs(angle - currentAngle);
                if (diff < currentMin) {
                    currentMin = diff;
                    minIndex = i;
    System.out.println("new minDifference at "+i+": "+diff);
            Double destinationAngle = angles.get(minIndex);
    System.out.println("DestinationAngle is "+currentAngle+" -> "+(destinationAngle - 180));
            if (destinationAngle < 180 + 10 || destinationAngle > 360 - 10) {
                throw new IllegalStateException("Angle is out of range: "+currentRotation.doubleValue()+" -> "+destinationAngle);
            currentRotation.set(destinationAngle - 180);
         * Calculate the angle between the vector horizontally to the left from the center
         * and the current point.
         * @param center point
         * @param point current point
         * @return angle in degree
        double angleBetween2Lines(Point2D center, Point2D point) {
            double slope2 = calculateSlope(center, point);
            double angle = Math.atan(slope2);
            if (point.getX() > center.getX()) {
                angle += Math.PI/2;
    System.out.println("Slope: "+slope2+" angle "+Math.toDegrees(angle));
            return Math.abs(Math.toDegrees(angle));
         * Caluculate the slope of the line defined by two points.
         * The first point is the center of a circle and the second
         * point roughly lies on the circle.
         * @param center point
         * @param point on the circle
         * @return slope of the connecting line.
        double calculateSlope(Point2D center, Point2D point) {
    System.out.println("center="+center+",point="+point);       
            double absSlope = Math.abs((point.getY() - center.getY()) / (point.getX() - center.getX()));
            if (point.getY() > center.getY()) {
                if (point.getX() > center.getX()) {
                    // bottom right
                    return -absSlope;
                } else {
                    // bottom left
                    return absSlope;
            } else {
                if (point.getX() > center.getX()) {
                    // top right
                    return absSlope;
                } else {
                    // top left
                    return -absSlope;
         * The main() method is ignored in correctly deployed JavaFX application.
         * main() serves only as fallback in case the application can not be
         * launched through deployment artifacts, e.g., in IDEs with limited FX
         * support. NetBeans ignores main().
         * @param args the command line arguments
        public static void main(String[] args) {
            launch(args);
       private class SteeringWheelGroup extends Group {
            public SteeringWheelGroup(int destinationWidth) {
                int topPadding = 0;
                Rectangle rect = new Rectangle(getImageWidth(), getImageWidth(), Color.RED);
                double scale = destinationWidth / rect.getWidth();
                rect.setScaleX(scale);
                rect.setScaleY(scale);
                Circle circle = new Circle(getImageWidth()/2, getImageWidth()/2, getImageWidth()/2, Color.BLUE);
                circle.setScaleX(scale);
                circle.setScaleY(scale);
                Group rotationGroup = new Group(/*rect,*/ circle);
                rotationGroup.setManaged(false);
                int width = getImageWidth();
                Rectangle clipRectangle = new Rectangle(0, 0, width, width / 2);
                Circle clipCircle = new Circle(width / 2, width / 2, width / 2);
                Shape clip = Shape.intersect(clipRectangle, clipCircle);
                rotationGroup.setClip(clip);
                this.getChildren().add(rotationGroup);
                //double h = calculateHeigthOverHorizon(angle, destinationWidth/2);
                //setTranslateY(-h+topPadding);
            public final int getImageWidth() {
                return 479;
    Here is how you can reproduce my effect:
    Grab the black handle
    Drag the mouse top and right until you approach the angle -90 (have an eye out on the console log)
    Let the mouse go: the handle will snap to 90 degree
    Grab the handle a second time and move further right
    You will see that the angle printed out do not match what you expect.
    Let the mouse go, the Handle snaps back to it's original position
    As the rotation does not happen around the polygon's center, I have to use a Rotaion effect, which is applied. While I can drag the shape from the rotated location the dragging is always measured from its base position.
    So what can I do to work around this?
    final Rotate rotationTransform = new Rotate(currentRotation.doubleValue(), centerPoint.getX(), centerPoint.getY());
    polygon.getTransforms().add(rotationTransform);
    If worse comes to worst, I can use a circular handle covering everything, then I can rotate around its center, but I would like to avoid this.

  • Mouse dragging events in NSWindow and NSView

    Hi, I have built and application that uses a single window that contains multiple components within it. The main component of the window is a custom NSView subclass that contains a number of CALayers. I want to be able to move these layers around the NSView subclass based on the mouseDown, mouseDragged, and mouseUp events entered by the user. I can detect and process mouse events fine within the NSView subclass, however, whenever I drag the mouse within the NSView subclass right after a mouseDown event, the WHOLE WINDOW will move. I do not want that to happen, that is, when I am dragging the mouse within my NSView subclass, I do not want the whole window to move. I want my CALayers, within the NSView, to move according to the mouse events that I am correctly tracking in the NSView subclass. I will very much appreciate any suggestions. Thank you very much in advance.

    Thank you very much for your response. Your tip is very useful. What I did before was change the window type in Interface Builder: replace the textured window with a regular window. This solved the problem, however, I could not find the property that needed to be adusted to control the window behavior. I learned something useful with your tip. Thanks again.

  • How to catch drag event in the title bar of a jframe

    Hi
    I want to catch the drag event in the title bar for jframe, because I have a few more window, dialogs, which I want to move along with my main window
    Thanks

    you can use a listener like tih one below...it works if you don't move to quickly.....
    class SynchroMover extends ComponentAdapter{
      private JFrame master;
      private JFrame[]slaves;
      private int currentX;
      private int currentY;
      public SynchroMover(JFrame master,JFrame[]slaves){
        this.master = master;
        this.slaves = slaves;
        currentX =(int) master.getLocation().getX();
        currentY =(int) master.getLocation().getY();
      public void componentMoved(ComponentEvent e){
        int dx = (int)master.getLocation().getX() - currentX;
        int dy = (int)master.getLocation().getY() - currentY;
        System.out.println(dx+" "+dy);
        for(int i=0;i<slaves.length;i++)
          slaves.setLocation((int)(slaves[i].getLocation().getX()+dx),(int)(slaves[i].getLocation().getY()+dy));
    currentX = (int)master.getLocation().getX();
    currentY = (int)master.getLocation().getY();
    the code isn't optimized...so you can probably do better

  • Mouse dragged event - problem(logic problem?)

    Hi! I have a window which is started by a frame. At the moment I have a Mouse Dragged event. The ideea is that I would like to drag the window to various parts of the screen but as it is the window flickers a lot and it keeps on jumping to various locations when dragging it. Is there a way to redraw and move the window only once the mouse button was released from the drag and not all the time?!
    Thank you.

    if i understood your question correct setVisible(false) when you grab it setVisivble(true) when you release it. If you want it to be still shown in the ori�ginal place while dragging make a second window that stays at the starting location and id removed after the first diappears.
    An even better solution would be to remember the location of the mouse in a pousepressed event and then wait for mousereleased. (and set a boolean true if the mouse pressed was inside the window).

  • [Solved] xcompmgr -- Drag events kill XOrg rendering (xcompmgr crash)

    To fix a problem I was having with direct draw applications glitching/ghosting https://bbs.archlinux.org/viewtopic.php … 1#p1384701 I implemented the fix I documented.
    Now, direct draw drag events kill all rendering in XOrg. It seems xcompmgr just silently dies and I have to kill and restart XOrg to get it working again. A simple example of this is dragging an image in Firefox. Input still works and the window manager is fine (I can still spawn terminals with my hotkeys). Killing xcompmgr doesn't fix the problem nor does restarting it.
    Anyone have any suggestions beyond switching to compiz/nouveau?
    Last edited by pilotkeller (2014-02-25 14:19:39)

    So I've managed to solve my problem.
    Thanks anonymous_user, you set me on the right path with the suggestion of compton. I checked its man page and it has abolished the -a flag. Didn't know why. Turns out, it's buggy and prone to these crashes.
    I'll edit my solution in my linked post noting what I've done.
    Thanks a million to you again anonymous_user, and you too headkase! You two are what make these forums amazing.

  • AWT Drag Events Not Registering

    Hi all,
    I have written up a small program (code is at the bottom) that uses the getToolkit().addAWTEventListener(new AWTEventListener() code. In it, it will listen for drag events. If it detects one, it will update a variable called currentPoint. Then I have a subclassed JPanel that everytime it paints, will display a rectangle at the current point.
    I then run the program and drag my mouse around for maybe 30 seconds. Things work 100% correct. After that though, it seems the AWTEventListener begins missing the events and the currentpoint doesn't update. This means the block that is following my mouse stops as my mouse cursor moves away during the drag. The point updates about a second later. So for example: If I am moving along the x-axis, the block follows me until say (10, 5) and then stops. My mouse then continues to move and it gets to (15,5) and then the block updates and jumps to that point. These actions steadily get worse and worse as I run the program.
    Does anyone have any idea what is occuring? I haven't given much thought but maybe the GC? You can also look at the output and there are no events processed during that time...
    Thanks,
    day
    Code:
    package main;
    import java.awt.AWTEvent;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Point;
    import java.awt.Rectangle;
    import java.awt.event.AWTEventListener;
    import java.awt.event.MouseEvent;
    import java.io.BufferedWriter;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.io.Writer;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    public class DragWindow extends JFrame
         private Point currentPoint = null;
         private PaintPanel paintPanel;
         private boolean dragging = false;
         public DragWindow()
              super("Drag Test");
              paintPanel = new PaintPanel(this);
              this.getContentPane().add(paintPanel);
              try
                    final PrintWriter out
                      = new PrintWriter(new BufferedWriter(new FileWriter("dragData.txt")));
                   addWindowListener(new ExitListener(out));
                   setSize(1280, 1024);
                   setLocation(0, 0);
                   setVisible(true);
                   getToolkit().addAWTEventListener(new AWTEventListener()
                           public void eventDispatched ( AWTEvent e )
                                Point point = ((MouseEvent)e).getPoint();
                                currentPoint = point;
                                System.out.println("Parsed this: X: " + point.x + ". Y: " + point.y);
                                out.write("Parsed this: X: " + point.x + ". Y: " + point.y + "\n");
                                out.flush();
                                if(e.getID() == MouseEvent.MOUSE_DRAGGED)
                                     String data = "MOUSE_DRAGGED: Event: " + e.paramString();
                                     System.out.println(data);
                                     out.write(data);
                                     out.flush();
                                     dragging = true;
                                else if(e.getID() == MouseEvent.MOUSE_RELEASED)
                                     String data = "MOUSE_RELEASED: Event: " + e.paramString();
                                     System.out.println(data);
                                     out.write(data);
                                     out.flush();
                                     dragging = false;
                                repaint();
                      }, AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK
              catch (FileNotFoundException e1)
                   e1.printStackTrace();
              catch (IOException e)
                   e.printStackTrace();
          * @return Returns the currentPoint.
         public Point getCurrentPoint ()
              return currentPoint;
          * @param currentPoint The currentPoint to set.
         public void setCurrentPoint ( Point currentPoint )
              this.currentPoint = currentPoint;
          * @return Returns the dragging.
         public boolean isDragging ()
              return dragging;
          * @param dragging The dragging to set.
         public void setDragging ( boolean dragging )
              this.dragging = dragging;
    package main;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Rectangle;
    import javax.swing.JPanel;
    public class PaintPanel extends JPanel
         DragWindow window;
         public PaintPanel ( DragWindow window )
              this.window = window;
         public void paintComponent(Graphics g)
              super.paintComponents(g);
              Graphics2D g2d = (Graphics2D)g;
              if(window.getCurrentPoint() != null && window.isDragging())
                   Rectangle rectPoint = new Rectangle(window.getCurrentPoint().x, window.getCurrentPoint().y, 20, 20);
                   g2d.fill(rectPoint);
    package main;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.io.PrintWriter;
    import javax.swing.JFrame;
    /** A listener that you attach to the top-level Frame or JFrame of
    *  your application, so quitting the frame exits the application.
    *  1998 Marty Hall, http://www.apl.jhu.edu/~hall/java/
    public class ExitListener extends WindowAdapter
         private JFrame frame;
         private PrintWriter outi;
         public ExitListener(PrintWriter o)
              outi = o;
          * @return Returns the frame.
         public JFrame getFrame ()
              return frame;
          * @param frame The frame to set.
         public void setFrame ( JFrame frame )
              this.frame = frame;
         public void windowClosing(WindowEvent event)
              outi.close();
              System.exit(0);     
    }

    i ran your code on my Pc and do not encounter the problem that you have described. The rectangle always follows my mouse when I drag, however, it isnt at the current point of the mouse. It stays a constant value below it.
    Also, GC is unnecessary. java auotmatically gc's when needed.
    I am unsure what may be wrong for you since your app seems to work fine for me, even after a steady 1.5 - 2 mins of dragging.

Maybe you are looking for

  • There is no sounds in my new iphpne4

    There is no sounds in my new iphpne4 including the speaker and the receiver and the headset. But when I restart it, it will have sounds for a minute sometimes. And sometimes not. When it have sounds, I just put it on my desk and do nothing, no sounds

  • How can i get my verizon bill bundled with century link?

    how can i get my verizon bill bundled with century link?

  • Problems with Samsung Kies

    After the launch of OS X the following message appears from Samsung Kies for a few seconds: "The download of the firmware for GT-i9000 has been completed. Check to see which model you are using and click here to quickly perform an update with previou

  • Creating Radio Button on Module pool Screen

    Hi Gurus, I am currently working on a program which involves module pool selection screen. In my selection screen i have placed 2 radio buttons, i have kept these radio buttons in same group. But when i am running the program both the radio buttons a

  • Cross Business Area posting restriction

    Dear Experts, Is it possible to restrict in Cross business area posting through configuration? I want to keep validation in cross business area posting. Sourav