Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / August 2006

Tip: Looking for answers? Try searching our database.

setProperty("headless","true") weirdness?

Thread view: 
Daisy - 08 Aug 2006 11:46 GMT
Can anyone provide insight on System.setProperty( "java.awt.headless" ,
"true" )?

I've been struggling with a HeadlessException in the line:
   JFrame frame = new JFrame( );

So I added System.setProperty( "java.awt.headless" , "true" ) before
the JFrame call.  However, JFrame still throws this error.   Shouldn't
setting the property inform the JVM that it is headless?

System.setProperty( "java.awt.headless" , "true" );
try {
   JFrame frame = new JFrame( );
   frame.getContentPane( ).add( c );
   frame.addNotify( );
} catch ( HeadlessException e ) {
   printStackTrace( );
}

It is a Redhat computer running Hotspot 1.5.0_07 and Tomcat 5.5.17.  It
is headless.  The application is a servlet that runs fine on linux
machines with monitors.  I tried the -Djava.awt.headless=true argument
long ago and still use it.

I'd really appreciate any insight on this problem,

Thanks!
Gordon Beaton - 08 Aug 2006 12:03 GMT
> Can anyone provide insight on System.setProperty(
> "java.awt.headless" , "true" )?
[quoted text clipped - 5 lines]
> the JFrame call. However, JFrame still throws this error. Shouldn't
> setting the property inform the JVM that it is headless?

I believe you need to set the property before
java.awt.GraphicsEnvironment is loaded and initialized.

/gordon

Signature

[ don't email me support questions or followups ]
g o r d o n  +  n e w s  @  b a l d e r 1 3 . s e

Stanimir Stamenkov - 08 Aug 2006 14:04 GMT
> I've been struggling with a HeadlessException in the line:
>     JFrame frame = new JFrame( );
>
> So I added System.setProperty( "java.awt.headless" , "true" ) before
> the JFrame call.  However, JFrame still throws this error.   Shouldn't
> setting the property inform the JVM that it is headless?

I believe that's what we expect - you can't construct a Frame given
you're in a headless environment, why do you need to?

> HeadlessException - Thrown when code that is dependent on a
> keyboard, display, or mouse is called in an environment that does
> not support a keyboard, display, or mouse.

Signature

Stanimir

Norman D. - 08 Aug 2006 14:15 GMT
Here is a link which might be helpful:

http://java.sun.com/developer/technicalArticles/J2SE/Desktop/headless/

--Norman

> Can anyone provide insight on System.setProperty( "java.awt.headless" ,
> "true" )?
[quoted text clipped - 23 lines]
>
> Thanks!
Daisy - 11 Aug 2006 12:43 GMT
Thanks everyone who gave advice!

Here's the revised code which resolved the problem:

System.setProperty( "java.awt.headless" , "true" );
       Toolkit tk = Toolkit.getDefaultToolkit( );

       try {
           // JFrame frame = new JFrame( );
           // frame.getContentPane( ).add( c );

           JPanel panel = new JPanel( );
           panel.add( c );
           panel.addNotify( );

In addition to setting the headless property, I had to swap from Frame
to Panel.

Thanks,

Jeff

> Here is a link which might be helpful:
>
[quoted text clipped - 29 lines]
> >
> > Thanks!


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.