Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.awt.HeadlessException when trying to retrieve the screen width and height #1

Open
isaacmaffeis opened this issue Dec 27, 2023 · 0 comments

Comments

@isaacmaffeis
Copy link
Owner

Code 1:

// single monitor configuration
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
screenWidth = screenSize.width;
screenHeight = screenSize.height;

Exception:

java.awt.HeadlessException
	at java.desktop/sun.awt.HeadlessToolkit.getScreenSize(HeadlessToolkit.java:186)
	at org.wallpaperwizardapp.wallpaperwizard.model.ImageResizer.screenSizeGetter(ImageResizer.java:88)
	at org.wallpaperwizardapp.wallpaperwizard.model.ImageResizer.resizeImage(ImageResizer.java:23)
	at org.wallpaperwizardapp.wallpaperwizard.Main.main(Main.java:42)

I have used this code for a multi-monitor configuration but the same exception comes back

Code 2:

// multi-monitor configuration
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
screenWidth = gd.getDisplayMode().getWidth();
screenHeight = gd.getDisplayMode().getHeight();

Exception:

java.awt.HeadlessException
	at java.desktop/sun.java2d.HeadlessGraphicsEnvironment.getDefaultScreenDevice(HeadlessGraphicsEnvironment.java:58)
	at org.wallpaperwizardapp.wallpaperwizard.model.ImageResizer.screenSizeGetter(ImageResizer.java:95)
	at org.wallpaperwizardapp.wallpaperwizard.model.ImageResizer.resizeImage(ImageResizer.java:23)
	at org.wallpaperwizardapp.wallpaperwizard.Main.main(Main.java:42)

I currently catch the exception and use the standard values of 1920 for the width and 1080 for the height

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant