Say I've got a JFrame with a null Layout. I'm trying to move a component in the JFrame when the mouseDragged event for the component is fired (Similar to how a Windows Listview works when you drag the column header). I just can't seem to get the arithmetic to position it.
So far, I've got...
The code in mouseDragged is completely awful, but I forget the code I had that worked better. What I'm basically looking for is, if the mouse is pressed say 4 pixels in to the component, when I drag, I want the left of the component to stay 4 pixels left of the mouse until I release it.Code:Point mPMouseDown = new Point(); public void mousePressed(MouseEvent me) { isArmed = true; mPMouseDown.setLocation((int)me.getX(),(int)me.getY()); this.repaint(); } public void mouseDragged(MouseEvent me) { int t = (int)mPMouseDown.getY(); int l = (int)mPMouseDown.getX(); this.setLocation((int)this.getLocation().getX()+(l/2),(int)this.getLocation().getY()); }
![]()




Reply With Quote