Drag Event Problem in ItemRenderer

Hi Everyone,
I faced the problem in Drag Drop event occur in the Item Renderer. Here i attach the screen shot. If any one know the solution please let me know.
Thanks in Advance,
Charles

Hi,
Actually the Datagrid, label and text boxes are in one Canvas. I use this Canvas in One ItemRenderer.mxml and the data are comes from XML file. I Called that ItemRenderer.mxml file into my Main Screen.mxml file. So the ItemRender is repeated based on my Input Data.
Thanks,
Charles

Similar Messages

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

  • I can't be the only person who has this problem - when a month ends on a Saturday I can't drag events into the next month and instead have to cut and paste - a real pain in the butt. I thought there was something called "scroll" but I can't find that

    I can't be the only person who has this problem with iCal- when a month ends on a Saturday I can't drag events into the next month and instead have to cut and paste - a real pain in the butt. I thought there was something called "scroll" but I can't find that.

    Yeah that works, but, it involves a click on the event, a click on edit, a click on the date, keystrokes, plus, since you can't see the next month you have to have a calendar in front of you so as to put it to the right date. It's easier just to cut it and advance the month and paste it, once you are in the right month you can move it around helter skelter willy nilly no problems. Although now that you mention it I will try it, maybe it is easier than cut and paste as I don't really care about the date, as long as it gets moved into the right month I can drag it around all I want.

  • How can I stop coalescing of mouse move/drag events in jdk1.6 ?

    Hello all,
    My application uses a [pen-based tablet|http://en.wikipedia.org/wiki/Graphics_tablet] to draw lines/curves. But the problem is: when I run my application, due to java’s default behavior of discarding the mouse events which occurs during the repaint call, the curves results in the set of joined straight lines.
    To overcome this problem, when searched over net, came across below link:
    [http://forums.sun.com/thread.jspa?messageID=10811388]
    I tried the option provided at the above URL i.e. overriding the below method of Component.java file:
    protected AWTEvent coalesceEvents(AWTEvent existingEvent,AWTEvent newEvent);
    But later found that, overriding this method worked fine for me for jdk1.5 but this solution did not work in case of jdk1.6. When reviewed the source of Component.java and EventQueue.java files in jdk1.6, found that this method is not having any implementation and simply returns “null” and the complete handling of coalescing of events occurs within EventQueue.java file’s local method which is mentioned below:
    private boolean coalesceEvent(AWTEvent e, int priority);
    As this method is part of EventQueue.java and also it is a private method, I am not finding any way to stop the coalescing of mouse move/drag events in jdk1.6.
    The main problem is that my application is purely based on jdk1.6 only.
    Can anybody help me out to solve this problem by providing any option of preventing the coalescing of mouse move/drag events in case of jdk1.6.
    Thank you.

    Look at the link I posted, you aren't double buffering correctly.
    I saw the other post you mistakenly made before you edited it. Not really a big deal, I was just wondering why you did that.

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

  • 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();                

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

  • InputField fire event problem in webDynpro

    I have one validation or Fire Event problem with respect to Inputfield in web Dynpro.
    I have one Input filed and created the context varible for that, then i mapped the context varible to the InputField, and i changed the context varible type as date.So , when i run the view , it will show the calender near to the text box to select the perticular date. On select of the perticular date. It will populate selected  date in to the inputField.
    On selection of the perticular date. Based on the date i want to generate the next 12 months date at runtime in different text boxes. But the only event available for the InputField is only "onEnter". This is not useful in my case, bcz on selection of the Date , the user may not use the Enter key. so , how can use the other events like onSelection or onChange events in the InputFields to reach my needs.
    Any one  give me the idea to solve this problem.
    Vijay

    Hello Vishal,
    You may also refer the sample code in the below link
    <a href="http://sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/0c0dcacd-0401-0010-b4bd-a05a0b4d68c8">http://sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/0c0dcacd-0401-0010-b4bd-a05a0b4d68c8</a>
    Regards,
    Sudeep.

  • More event problems

    Hello again, I have yet another event problem. When I try to use this code I get an error saying Abstract class actionPerformed is not implemented in non- abstract class TableWindow. I'm not quit sure how I'm supposed to implement it.

    Here is what I believe to be the relevant code. addWindowListener works but addFocusListener returns the error.
    // Table window
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class TableWindow extends Frame implements ActionListener
    public TableWindow ()
    Create Window
    super ("Test Window");
    setBackground (SystemColor.control);
    setLocation (0, 0);
    setLayout (new GridLayout (5, 5));
    addWindowListener (new WindowAdapter ()
    public void windowClosing (WindowEvent e)
    try
    if (Connected == true)
    // Close the Statement
    stmt.close ();
    // Close the connection
    con.close ();
    catch (SQLException sqle)
    dispose ();
    System.exit (0);
    tPane = new JTabbedPane ();
    tPane.addChangeListener (new ChangeListener ()
    public void stateChanged (ChangeEvent c)
    //Status.setText ("Clicked");
    tablePane = new JPanel ();
    recordPane = new JPanel ();
    recordPane.addFocusListener(new FocusListener()
    public void focusGained(FocusEvent e)
    Status.setText ("Clicked");
    queryPane = new JPanel ();
    TName1 = new TextField (25);
    TName2 = new TextField (25);
    TName3 = new TextField (25);
    idField = new TextField (10);
    idField2 = new TextField (10);
    TitleField = new TextField (25);
    TitleField2 = new TextField (25);
    result = new TextArea ("Under Construction", 5, 30);
    NewT = new Button ("New Table");
    NewR = new Button ("New Record");
    NewQ = new Button ("New Query");
    NewT.addActionListener (this);
    NewR.addActionListener (this);
    NewQ.addActionListener (this);
    TNameLabel1 = new Label ("Enter name of table here");
    TNameLabel2 = new Label ("Enter name of table here");
    TNameLabel3 = new Label ("Enter name of table here");
    idLabel = new Label ("Enter movie ID here");
    TitleLabel = new Label ("Enter title of Movie here");
    TitleLabel2 = new Label ("Enter title of Movie here");
    tablePane.add (TNameLabel1);
    tablePane.add (TName1);
    tablePane.add (NewT);
    recordPane.add (TNameLabel2);
    recordPane.add (TName2);
    recordPane.add (idLabel);
    recordPane.add (idField);
    recordPane.add (TitleLabel);
    recordPane.add (TitleField);
    recordPane.add (NewR);
    //recordPane.add (tableChoice);
    queryPane.add (TNameLabel3);
    queryPane.add (TName3);
    queryPane.add (TitleLabel2);
    queryPane.add (TitleField2);
    queryPane.add (NewQ);
    queryPane.add (result);
    Status = new Label ("");
    // make the window and add components to it
    tPane.addTab ("Table", tablePane);
    tPane.addTab ("Record", recordPane);
    tPane.addTab ("Query", queryPane);
    add (tPane, BorderLayout.CENTER);
    add (Status, BorderLayout.SOUTH);
    pack ();
    setVisible (true);
    public static void main (String args [])
    ConnectToDatabase ("vdds");
    TableWindow tw = new TableWindow ();
    }

  • Drag events in Robot class

    I am using the Robot class in jdk1.3.1 to record and playback user input. I am getting the list of events and then traversing on it to do the appropriate action, mouse move, key events are played back fine, but I am unable to do mouse drag event.
    Here is simplified version of the code:
    for(int i = 0; i < aListEvents.size(); i++)
    AWTEvent event = (AWTEvent)aListEvents.get(i);
    Component c = (Component)event.getSource();
    int id = event.getID();
    switch(id)
    case MouseEvent.MOUSE_MOVED:
    int x = ((MouseEvent)e).getX();
    int y = ((MouseEvent)e).getY();
    m_robot.mouseMove(x,y);
    break;
    case KeyEvent.KEY_PRESSED:
    m_robot.keyPress(((KeyEvent)e).getKeyCode());
    break;
    case MouseEvent.MOUSE_DRAGGED:
         // do component drag
    break;
    Is there a way to mimic the drag event during playback and drag the object that was dragged during record?
    Any suggestions would be greatly appreciated!!
    Thanks :)

    This is an old posting, so the answer is probably too late for mamta and has also been answered elsewhere. But for whoever comes across this one, share my piece of experience:
    There's no one-to-one mapping between Java events and the system events (which is what Robot is refering to).
    After all, a MOUSE_DRAGGED is nothing but a MOUSE_MOVE after a MOUSE_PRESSED. So you can send a MOUSE_DRAGGED along to the robot as a mouseMove, because the Robot/system keeps in mind that the mouse button has been pressed before and therefor the event will appear in the Java event queue as a MOUSE_DRAGGED.
    Similar is MOUSE_CLICKED which needn't be replayed at all, because sending a MOUSE_PRESSED and a MOUSE_RELEASED to the Robot will automatically produce a MOUSE_CLICKED in the Java event queue as well.
    Same with the key strokes.

  • Consuming extra mouse drag events?

    Hi,
    In my mouse drag listener, there is a bit heavy processing that can take slightly long time (doing some real time computation). If I move the mouse fast, then there would be a long pause before processing catch up.
    So my question is that if it is possible to remove some mouse drag events in the queue s.t. my computation only takes on the latest drag event.
    I tried java.awt.Toolkit.getDefaultToolkit().getSystemEventQueue().peekEvent(), but it always returns null.
    Anyone could give a hint? Thanks a lot.

    This heavy processing should be done in a new thread and not the event thread. If the event thread is busy processing, it's not going to be able to respond to drag events. Once you do that, it would be easy to set a flag in that thread to notify it to stop processing and start with new values.

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

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

  • Simulating mouse drag events?

    Hi all,
    I am wrinting unit tests for my swing application. For one test I want to simulate a drag event over a panel. I have tried JFCUnit, but does not seem to work for this, so I am trying to write my own.
    I create 3 mouse events and post them on the system event queue. A mouse press event, a mouse drag event and a mouse release event. MouseEvent's do let you specify a drag start and a drag end point in their constructor. So I have tried using both, but neither works.
    Am I doing anything wrong? The component I'm operating on gets the mouse pressed and mouse released events, but thats all.
    any help much appreciated,
    Justin

    I tried using the Robot class alright, but it does really wierd things. I sometimes doesn't work for simulating dragging events. I have a component that you can drag anywhere on the screen using the mouse, without having to use the titlebar. I am trying to test this dragging, but with the robot class, it looks like it goes into an infinate recursion. The mouseDragged method gets executed thosands of times, and you can see the panel shifting from its origional position to the new position and back again for a few seconds. Could be a bug in Robot class.

Maybe you are looking for

  • Import bookmarks from another pc using firefox browser

    I know to go to sync, but I cannot put in my birthdate because the dropdown box doesn't work on the old computer from which I want to export my bookmarks.

  • Questions and answers about ordering Recovery DVDs

    There are some Frequently Asked Questions about the ordering process for Recovery DVDs: Questions about the ordering process and the prices Questions about delivery and shipment Questions about the technical background More Info: http://aps2.toshiba-

  • Certification for WM

    Hi I know this question has been posted before, but I didnt find the answer I was looking for. I am interested in WM certification. Is the SAP WM certification called : SAP Consultant Certification Solution Consultant SCM u2013 WM & LE with mySAP ERP

  • Form to echo data before submit

    I would like to capture or echo the data from a form before the submit button - I can get a new browser to open but cannot get the data to show - is this possible?  Thank you.

  • OpenJPA plugin for Eclipse?

    Hi All, Is there an OpenJPA plugin for Eclipse? I so, what does it do and is it available for Eclipse version 3.2.2? Thanks.