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

D

Daisy

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!
 
G

Gordon Beaton

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?

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

/gordon
 
S

Stanimir Stamenkov

Daisy said:
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?
 
D

Daisy

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top