Results 1 to 3 of 3
  1. #1
    diolu is offline Member
    Join Date
    Jan 2017
    Posts
    26
    Rep Power
    0

    Default Dimension in true dimension units in javafx

    I am completely new to GUI programming and I am reading the relevant chapter of the book "Introduction to java programming" by Daniel Liang. One thing disturbs me. Each time a dimension need to be provided it is in pixels. But in the area of HiDipi, it is usually a very bad idea. Isn't there a possibility to natively support true dimension in cm or inches. Reading the API, it doesn't seem to be supported, at least natively (all the Double value are always pixels, of course, we could play with properties to specify a percentage, etc). Why is it so? What's the best way to have a GUI whose size is independent of the physical pixel density of the monitor?

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Dimension in true dimension units in javafx

    Quote Originally Posted by diolu View Post
    What's the best way to have a GUI whose size is independent of the physical pixel density of the monitor?
    Or what is the best way to have a GUI whose size is independent of the physical size of the screen? What happens if you specify a 10" width requirement on a 3" screen? The problem works both ways (which I believe is why Android supports multiple screen values depending on the device).

    All I can recommend is to compute the size you need. The following will provide pixel density per inch. You could then write a static method to convert from your units of choice to pixels.
    Java FX Code:
          int res =  Toolkit.getDefaultToolkit().getScreenResolution();
    Regards,
    Jim
    Last edited by jim829; 02-14-2017 at 06:41 PM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    398
    Rep Power
    5

    Default Re: Dimension in true dimension units in javafx

    'Agree with Jim:pixels as primary unit plus conversion to absolute length is the way to go. It should take no more than one simple method toPixel() if you want to work with inches or mm. JavaFX also gives you the conversion factor with Screen.getPrimary().getDpi();

Similar Threads

  1. Change dimension of image
    By cselic in forum AWT / Swing
    Replies: 3
    Last Post: 08-29-2010, 09:23 PM
  2. Arrays -changing from 1 dimension to 2d
    By dbashby in forum New To Java
    Replies: 36
    Last Post: 10-16-2009, 10:58 PM
  3. applet and dimension
    By mensaFool in forum New To Java
    Replies: 5
    Last Post: 09-15-2009, 04:37 AM
  4. Replies: 5
    Last Post: 05-18-2009, 12:42 PM
  5. noob: two-dimension array
    By bobmasta5 in forum New To Java
    Replies: 5
    Last Post: 03-15-2009, 11:42 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •