I want a user to draw rectangles in a Indesign fashion. Yoy should be able to resize and so on. The problem is that when I drag the mouse real fast the rectangle moves to a position that is not correct
If someone could look at this code. If you press the 1 button you can select rectangles and move them. If you press the 2 button you can drag rectangles. Please try and drag them fast and you will see them jump around.
I use the technique that if the offset Point. ( The first point on the mouse ) i less than the mouse coordinate in the drag then the x , y of the rectangle becomes the drag mouse coordinate. I think the problem lies here but I don't know why and what I'm doing wrong. Here is my code. It is under process so It is not built with speed in mind. If you have another approach to my problem then please tell me.
Works better now. I changed the class names so you can run this as–is without name–clashing. Made changes in each class, mostly finishing up the mouse code. Moving the Block rect requires a different technique than dragging its sides/corners. mouseReleased is still rough but I think enough of your question is answered now.
But there is still a major problem when resizing the block
When I place a block it works fine. When i want to resize it and drag ex upper right corner real fast the block "JUMPS". It means it does not retain x and y coordinates. I don't know why but and I can't it. Do you know what the problem is?
Do you mean that the entire Block moves with no edges/parts stationary? Or that the lines of the Block cannot be drawn quickly enough with rapid movement and appear jumpy? Using the TesterRx class, when I drag the upper right corner slower or faster, the block resizes okay. The lower left corner remains stationary, the top side and right side move with the mouse pointer. The y coordinate of the upper left corner changes and the x coordinate of the lower right corner changes — but I would say this is the expected behavior. The entire block does not translate when dragging a corner or side edge. The moving lines, especially the ones connected to the mouse pointer, do appear jumpy when the mouse is moved very fast. But this seems normal/not excessive for this kind of program.
Ok thanks.... I tried it in Indesign but it doesn't get jumpy there.
I have tried to create a rule that is for the grid mesurement. The TesterRX and the new panel is in the same JScrollpane. When i try to scroll the JscollPane the RuleRx flickers a lot. It is a very small JPanel. I there a better way of doing this beside using image.
This is a mesure in mm and a pixel is 0.353 mm so I have to cheat a little as you can see.
I added your RulerRx class and the RectsRx class to a JPanel and put it in a JScrollPane and it worked okay — no flickering, jerkiness or rough behavior.
Is there anything special that I should think about when designing this. Is there a better approach on dragging the rectangles? Or perhaps the onmose over method.
// Mathias
SCJP1.4
I want my playground back. Here, I'll give you this tiny ad for it:
Gift giving made easy with the permaculture playing cards