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 / General / July 2006

Tip: Looking for answers? Try searching our database.

JFrame called Ghost doesn't show

Thread view: 
Paul Hamaker - 07 Jul 2006 09:18 GMT
Just found out that a JFrame called Ghost won't show. Inside joke,
easter egg?
--------------------
Paul Hamaker, SEMM, teaching ICT since 1987
http://javalessons.com
Chris Uppal - 07 Jul 2006 10:17 GMT
> Just found out that a JFrame called Ghost won't show. Inside joke,
> easter egg?

Works for me with 1.5.0 on WinXP.  What JDK/OS are you using ?

   -- chris
Paul Hamaker - 07 Jul 2006 22:08 GMT
Did you run something  like this ? default package ?

public class Ghost extends javax.swing.JFrame {
 public static void main(String[] args) {
   new Ghost().setVisible(true);
 }
}

I started another topic here
http://forum.java.sun.com/thread.jspa?threadID=750666

--------------------
Paul Hamaker, SEMM, teaching ICT since 1987
http://javalessons.com
Paul Hamaker - 08 Jul 2006 22:13 GMT
I really wasn't kidding, what's up what this, no harm in trying it
yourself :

public class Ghost extends javax.swing.JFrame {
 public static void main(String[] args) {
   Ghost app=new Ghost();
   app.setSize(400,300);
   app.setVisible(true);
 }
}

I ran it on WinXP home Java1.5.0_06.
Luke Webber - 09 Jul 2006 06:15 GMT
> I really wasn't kidding, what's up what this, no harm in trying it
> yourself :
[quoted text clipped - 8 lines]
>
> I ran it on WinXP home Java1.5.0_06.

Hey, you're right. Spooky! <g>

Luke
Andrew T. - 09 Jul 2006 08:22 GMT
> I really wasn't kidding,

Your initial post had me believing you were (and you had a
very strange sense of humor - not that that's a bad thing)

>...what's up what this, no harm in trying it
> yourself :

I prefer a self contained demo., which also tests the assertion
that the frame's title has something to do with it.  That was
suggested in the Sun thread.

<sscce>
import java.awt.*;
import javax.swing.*;

class Ghost extends JFrame {
 Ghost() {
   setPreferredSize(new Dimension(200,200));
   getContentPane().add( new JLabel("Boo!") );
   pack();
 }
}

class Spirit extends JFrame {
 Spirit() {
   setPreferredSize(new Dimension(200,200));
   getContentPane().add( new JLabel("Drink!") );
   pack();
 }
}

class TestGhost {
 public static void main(String[] args) {
   Ghost ghost1 = new Ghost();
   Ghost ghost2 = new Ghost();
   ghost2.setTitle("Spirit");

   ghost1.setVisible(true);
   System.out.println( "ghost1: " + ghost1.getTitle() );
   ghost2.setVisible(true);
   System.out.println( "ghost2: " + ghost2.getTitle() );

   Spirit ghost3 = new Spirit();
   Spirit ghost4 = new Spirit();
   ghost4.setTitle("Ghost");

   ghost3.setVisible(true);
   System.out.println( "ghost3: " + ghost3.getTitle() );
   ghost4.setVisible(true);
   System.out.println( "ghost4: " + ghost4.getTitle() );

   JPanel p = new JPanel( new BorderLayout() );
   JTextArea ta = new JTextArea();
   ta.append(System.getProperty("java.version") + "\n");
   ta.append(System.getProperty("os.name") + "\n") ;
   ta.append( ghost1.isVisible() + " " ) ;
   ta.append( ghost2.isVisible() + " " ) ;
   ta.append( ghost3.isVisible() + " " ) ;
   ta.append( ghost4.isVisible() + " " ) ;

   JOptionPane.showMessageDialog( (Component)null, ta );
 }
}
</sscce>

My results here are..
 1.5.0-beta
 Windows XP
 true true true true

While only the two 'Spirit' class frames actually show.

Andrew T.
Andrew T. - 09 Jul 2006 08:46 GMT
> ..only the two 'Spirit' class frames actually show.

This problem also affects any class called  'Ghost'
which extends java.awt.Frame.  The problem does
not seem to affect a Window.

Andrew T.
Andrew T. - 09 Jul 2006 09:23 GMT
If you further alter this source to extend Ghost..

> <sscce>
> import java.awt.*;
[quoted text clipped - 7 lines]
>   }
> }

class GhostChild extends Ghost {
 GhostChild() {
   super();
 }
}

.....
> class TestGhost {
>   public static void main(String[] args) {
>     Ghost ghost1 = new Ghost();

 GhostChild ghost2 = new GhostChild();

...

GhostChild appears OK.

This problem seems very specific to sub-classes of
Frame/JFrame called 'Ghost', but not their children.

So far, we only have test results for Windows boxes
(AFAIU), I would be interested to hear any test results
for other OS's.

Andrew T.
Chris Uppal - 10 Jul 2006 12:39 GMT
> Did you run something  like this ? default package ?
>
[quoted text clipped - 3 lines]
>   }
> }

No, I had understood you to be talking about the name of the frame, not the
name of the class it is an instance of.

Trying it (with AWT frames), I see exactly what you are seeing ;-)
Interesting...

It seems only to happen on Windows -- at least, a quick test with a 1.4 JVM on
Linux did not show the effect.

I spent some time trying to find the source of the effect in the code -- in
fact I wasted most of yesterday :-(   Couldn't find it.

The string "Ghost" does not appear in JVM.DLL (case-insensitive).  It appears
as a "utf8" constant pool entry in only two classes in rt.jar, neither of which
is relevant (the name of the constant static integer field,
sun.awt.shell.Win32ShellFolder2.ATTRIB_GHOSTED, and the method name
java.net.authenticator.requestingHost()).

At the implementation level (in case anyone's interested), the call to
setVisible(true) ends up in the peer's native method
sun.awt.windows.WComponentPeer.pShow().  The JNI implementation just sends a
custom Windows message with value 0x8004 to the real Windows window.  That
message is ignored if the AWT frame's class is named "Ghost", and acted on
otherwise.  There is no conditional code in the place where the message is
received. I can show/hide the Window by using the normal Win32 APIs directly
but not by using them to send the custom message.  I'm pretty sure that's
because the Windows windows has not been set up with a WindProc, whereas all
other Frames have one.  I haven't been able to find any conditional code to
cause that effect, however, and having spent too long getting that far, I just
gave up.

The fact that it /is/ so well hidden, suggests that the Easter egg theory may
be correct.  Surely legitimate code (even /bad/ legitimate code as suggested by
"PofN") wouldn't actually be hidden...

   -- chris
Andrew T. - 11 Jul 2006 08:27 GMT
..
> > public class Ghost extends javax.swing.JFrame {
> >   public static void main(String[] args) {
> >     new Ghost().setVisible(true);
> >   }
> > }
..
> Interesting...
>
> It seems only to happen on Windows -- at least, a quick test with a 1.4 JVM on
> Linux did not show the effect.
>
> I spent some time trying to find the source of the effect in the code --

(not resolved)
..
> The fact that it /is/ so well hidden, suggests that the Easter egg theory may
> be correct.  Surely legitimate code (even /bad/ legitimate code as suggested by
> "PofN") wouldn't actually be hidden...

Now that it is established as a bug specific to Windows,
do you intend to lodge a bug-report, Paul?

I think it's important it be 'findable' in the bug database,
even if only as a warning* to other developers.

* Assuming Sun decides it is not worth fixing.

Andrew T.
Paul Hamaker - 11 Jul 2006 10:22 GMT
> Now that it is established as a bug specific to Windows,
> do you intend to lodge a bug-report, Paul?
Already did.
Andrew T. - 11 Jul 2006 10:36 GMT
> > Now that it is established as a bug specific to Windows,
> > do you intend to lodge a bug-report, Paul?

> Already did.

Where?  I cannot see it amongst these results.
<http://bugs.sun.com/bugdatabase/search.do?process=1&category=&bugStatus=&subcate
gory=&type=&keyword=ghost
>

Andrew T.
Paul Hamaker - 16 Jul 2006 08:37 GMT
Andrew T. schreef:
> Where?  I cannot see it amongst these results.
My report has been assigned an internal review ID of 745063, which is
NOT visible on the Sun Developer Network (SDN).
Andrew Thompson - 16 Jul 2006 13:05 GMT
> Andrew T. schreef:
> > Where?  I cannot see it amongst these results.
> My report has been assigned an internal review ID of 745063, which is
> NOT visible on the Sun Developer Network (SDN).

Maybe a bug mentioning the word 'ghost' suffers the
same fate as a Frame.    ;-)

Andrew T.
Thomas Hawtin - 16 Jul 2006 20:03 GMT
> Maybe a bug mentioning the word 'ghost' suffers the
> same fate as a Frame.    ;-)

I've got an "incident review" without a bug ID involving Swing 'Timer'
not firing that must be two and a half years old. Mind you, I have
changed e-mail address in that period.

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

PofN - 09 Jul 2006 09:13 GMT
> Just found out that a JFrame called Ghost won't show. Inside joke,
> easter egg?

Bug caused by a hack.

Dialogs always need a parent frame. If you don't provide one Java
creates an internal, empty and hidden one, a "Ghost". Such a frame
should never be shown. Some idiot at Sun descided to use the title as a
"never show" flag. How that got past Sun's QA? Well, Sun doesn't have a
QA.
Andrew T. - 09 Jul 2006 09:54 GMT
> > Just found out that a JFrame called Ghost won't show. Inside joke,
> > easter egg?
[quoted text clipped - 3 lines]
> Dialogs always need a parent frame. If you don't provide one Java
> creates an internal, empty and hidden one, a "Ghost".

What leads to to that conclusion?

My investigations suggest otherwise.
1.  This affects AWT as well as Swing, and the programmer
must specify an owner for AWT dialogs - without exception.
2.  Tracing the JDialog source back suggests that when it is
constructed with no owner, it ends up with a SharedOwnerFrame
(extending Frame) defined in SwingUtilities.
3.  The string 'ghost' only appears once in any source* within the
java or javax packages (and it is a non-relevant hit in a java.net
class)

* J2SDK 1.5.0 (an early version)

Did I miss something?

Andrew T.


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



©2009 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.