• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Problem when repainting rectangles

 
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

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.

 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks alot

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?
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


// Mathias
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Have you seen how rulers are added to a custom component in the tutorial page How to Use Scroll Panes?
It is demonstrated in the section Providing Custom Decorations.
 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!

It worked for me now. Many thanks.

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
 
I want my playground back. Here, I'll give you this tiny ad for it:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic