Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get the screen DPI in java?
    primarykey
    data
    text
    <p>I am developing an app for which I need the screen DPI.. I checked a few forums and got a code snippet which goes as follows:</p> <pre><code>Dimension screen = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); System.out.println("screen width: "+screen.getWidth()); System.out.println("screen height: "+screen.getHeight()); int pixelPerInch=java.awt.Toolkit.getDefaultToolkit().getScreenResolution(); System.out.println("pixelPerInch: "+pixelPerInch); double height=screen.getHeight()/pixelPerInch; double width=screen.getWidth()/pixelPerInch; double x=Math.pow(height,2); double y=Math.pow(width,2); </code></pre> <p>But whatever be the value of my screen resolution, the <code>pixelPerInch</code> value remains the same at 96. What is the problem with the code??</p> <p>I got another <code>swt</code> code for the same thing which goes as follows:</p> <pre><code> import org.eclipse.swt.graphics.Device; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class MainClass { public void run() { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Display Device"); createContents(shell); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); } private void createContents(Shell shell) { Device device = shell.getDisplay(); System.out.println("getBounds(): "+ device.getBounds()); System.out.println("getClientArea(): "+device.getClientArea()); System.out.println("getDepth(): "+device.getDepth()); System.out.println("getDPI(): "+device.getDPI()); device.setWarnings(true); System.out.println("Warnings supported: "+device.getWarnings()); } public static void main(String[] args) { new MainClass().run(); } </code></pre> <p>But again here also whatever be my screen resolution, the <code>getDPI()</code> returns the same value of 96.. What is going wrong?? Is my code wrong or am I interpreting it in a wrong way??</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload