File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes getScreenSize() method giving java.awt.HeadlessException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "getScreenSize() method giving java.awt.HeadlessException" Watch "getScreenSize() method giving java.awt.HeadlessException" New topic
Author

getScreenSize() method giving java.awt.HeadlessException

teja popuri
Greenhorn

Joined: Apr 14, 2012
Posts: 2
Hi,

I am getting HeadlessException for getScreenSize() method.Please find the below sample code for more details.

Dimension dim = null;
try{
dim = Toolkit.getDefaultToolkit().getScreenSize();
}catch(Exception e){
e.printStackTrace();
}

The getScreenSize() method is not working in Java 1.6.But it is working in 1.4.
Recently we have upgraded the java to 1.6.

Can you please help me on this issue ?|
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Also, please BeForthrightWhenCrossPostingToOtherSites
http://www.java-forums.org/new-java/58345-getscreensize-method-giving-java-awt-headlessexception.html

edit
http://www.javaprogrammingforums.com/awt-java-swing/15163-getscreensize-method-giving-java-awt-headlessexception.html


luck, db
There are no new questions, but there may be new answers.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19542
    
  16

I've seen from one of these other threads that you're calling this code from a JSP file (as shown by stack trace element at com.ibm._jsp._Translation._jspService(_Translation .java:158)).
Are you aware that calling this method from a JSP would return the server's screen size, not the client's? You can only get the client screen size from an applet, and that probably still requires a signed applet.

If you really do need to get the server's screen size, add -Djava.awt.headless=false to your JVM options.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
teja popuri
Greenhorn

Joined: Apr 14, 2012
Posts: 2
Hi Rob,

Thanks for your reply.

yes.I am calling it in JSP page.

It is not working in JSP page with JAVA 1.6

But it is working in JSP page with JAVA 1.4.


Any idea on this issue?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19542
    
  16

Which screen size are you trying to get? That of the client or the server?
If it's the server, does the server even have a screen size to return? If it's a Linux or Unix server without any windowing system (like X11 or Xorg), you will never be able to get the screen size because there simply isn't any.
Vinodh Avala
Greenhorn

Joined: Jan 09, 2013
Posts: 1
I have encountered the java.awt.headlessexception when the code I developed moved from Windows environment to AIX environment.

The code snippet is Dimension.getDefaultToolKit().getScreenSize(). Tried a lot in forums. 2 viable options are using System.setProperty() and setting java.awt.headless=true on the console. If you use the former, have to be set even before class loading happens (I felt complicated). The latter is not recommended in enterprise applications (as the web admin has to set it every time the JVM is restarted).

So, I opted for Javascript (screen.width and screen.height) parameters and added them to the request string to access in my servlet. Finally worked!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getScreenSize() method giving java.awt.HeadlessException
 
Similar Threads
How to open a Maximised Window (urgent)
canExecute method of File?
size of the frame
How to set resolution of the screen
Full screen mode in Netbeans