• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ruler in mm

 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my program a user can draw shapes by using the mouse. I also have a Ruler to show the user where they are in mm on the drawing panel.

My problem is that I can't get the pixel to mm convention to work properly.
I only want to show every 5 mm in the ruler but I don't get It accurate.

A pixel is 0.353 mm and a mm 2.835 pixles. How can I make this as accurate
as possible so that when the ruler is over the 10mm line it's showed as
10 mm and not 9.454 or 10.3434 ( just an example ) Help would be very appreciated.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

A pixel is 0.353 mm and a mm 2.835 pixles.


This depends on the screen resolution.

Here is a similar post on the Sun forums.
 
Rob Spoor
Sheriff
Pie
Posts: 20611
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Screen resolution and screen size.

On a 17" TFT screen with 1280x1024 resolution a pixel is smaller than on a 19" TFT screen with the same resolution.
 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please explain. Do I need to take screen resolution and screensize in concern? Why and how?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, on a bigger screen with the same number of pixels, the pixels consequently have to be bigger, don't they?

Take a look at java.awt.Toolkit.getScreenResolution
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mathias Nilsson:

A pixel is 0.353 mm and a mm 2.835 pixles. How can I make this as accurate
as possible so that when the ruler is over the 10mm line it's showed as
10 mm and not 9.454 or 10.3434 ( just an example ) Help would be very appreciated.


I'm not sure what you mean by "accurate". Showing 10mm wouldn't be "accurate", because there is no pixel on your screen that is exactly at 10mm (assuming the resolution that you are working with).
 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My problem is this. I have a horizontal and a Vertical ruler that
shows every 5mm. 0, 5 ,10 , 15 and so on.

In my top panel I have x and y Spinners that shows the x and y and that can be changed by the user.

How can I sync these two? When I move the mouse and hit 0,5,10 mm in the ruler I want the spinners to show these values even if they may be 0, 5,2, 9.88
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the only legitimate choices are whole number, integer values, then this isn't a problem - just choose the closest whole number. If the user can legitimately choose fractional values, then this is slightly more difficult. You have to choose a smallest allowed increment and just choose the closest increment to the mouse click rather than the closest integer value. Of course, you have to make sure your smallest increment can be easily selected based on pixel sizes too! You don't want to have .0001 mm accuracy, because you can't realistically select that small of an increment through clicking pixels with the mouse.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic