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.
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
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).
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
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
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.
-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Live a little! The night is young! And we have umbrellas in our drinks! This umbrella has a tiny ad: