Fetching screen resolution using Java

0 votes

Can someone guide me how can I fetch the screen resolution (width x height) in pixels using a JFrame and Java swing methods?

Sep 20, 2018 in Java by v.liyyah
• 1,300 points
593 views

1 answer to this question.

0 votes

You can fetch the screen resolution using the Toolkit.getScreenSize() method of Java. Try following the below code:

Dimension screenRes = Toolkit.getDefaultToolkit().getScreenSize();
double width = screenRes.getWidth();
double height = screenRes.getHeight();

If you have a multi-monitor configuration, you need to use the following :

GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
int width = gd.getDisplayMode().getWidth();
int height = gd.getDisplayMode().getHeight();

If you want to get the screen resolution in DPI you'll have to use the getScreenResolution() method on Toolkit.

For more info you can refer below:

answered Sep 20, 2018 by anto.trigg4
• 3,420 points

Related Questions In Java

0 votes
2 answers

How do I get the current date and time using Java?

If you require a time stamp in ...READ MORE

answered Aug 23 in Java by Sirajul
• 32,100 points
100 views
0 votes
2 answers

How can I create File and write data in it using Java?

import java.io.BufferedWriter; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; public class WriteFiles{ ...READ MORE

answered Jul 26, 2018 in Java by samarth295
• 2,190 points
108 views
0 votes
1 answer

How can I read a large text file line by line using Java?

// Open the file FileInputStream file = new ...READ MORE

answered May 2, 2018 in Java by parth295
• 4,640 points
54 views
0 votes
2 answers

Store String inside a File using Java

We can use Apache Commons IO. It ...READ MORE

answered Jul 20, 2018 in Java by Sushmita
• 6,880 points
47 views
0 votes
1 answer

revalidate() vs repaint() in Java Swing

You need to call repaint() and revalidate() both in order ...READ MORE

answered Sep 19, 2018 in Java by code.reaper12
• 3,450 points
780 views
0 votes
1 answer

How to change selection listener in JComboBox?

It should respond to ActionListeners, like this: combo.addActionListener (new ...READ MORE

answered Nov 15, 2018 in Java by Frankie
• 9,810 points
81 views
0 votes
1 answer

Describe Heavy Weight Components Mean In Java Programming?

Heavy weight components like Abstract Window Toolkit ...READ MORE

answered Nov 28, 2018 in Java by Frankie
• 9,810 points
51 views
0 votes
1 answer

First panel added to a frame disappears

The default layout of a JFrame (or more specifically ...READ MORE

answered Mar 1 in Java by developer_1
• 3,300 points
30 views
0 votes
1 answer

Retrieve all the implementations of an interface in Java

Hi...I think you can achieve this by ...READ MORE

answered Jul 23, 2018 in Java by anto.trigg4
• 3,420 points
814 views
0 votes
1 answer

Setting time zone of a java.util.Date

You can make use of the following ...READ MORE

answered Aug 14, 2018 in Java by anto.trigg4
• 3,420 points
4,426 views