| Author |
Ruler in mm
|
Mathias Nilsson
Ranch Hand
Joined: Aug 21, 2004
Posts: 367
|
|
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.
|
SCJP1.4
|
 |
Nathan Pruett
Bartender
Joined: Oct 18, 2000
Posts: 4121
|
|
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.
|
-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
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.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Mathias Nilsson
Ranch Hand
Joined: Aug 21, 2004
Posts: 367
|
|
|
please explain. Do I need to take screen resolution and screensize in concern? Why and how?
|
 |
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
|
|
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
|
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
|
 |
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
|
|
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
Joined: Aug 21, 2004
Posts: 367
|
|
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
Joined: Oct 18, 2000
Posts: 4121
|
|
|
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.
|
 |
 |
|
|
subject: Ruler in mm
|
|
|