Wednesday, July 1, 1998

Question

Can anyone explain to me why show() is deprecated in java.awt.Component but not in java.awt.Window?

Answers

Nobody came up with a really convincing answer, which leads me to suspect that this is simply a mistake Sun made, intentionally or otherwise. The bottom line seemed to be that Window.show() not only makes the window visible but also brings it to the front if it's already visible. Thus its behavior is a little different than Component.show(). Bill Pugh explains:

The semantics of show() for Window are slightly different. If the Window is already visible, the window is moved to front. While for components, show() simply made the component visible. I'm guessing that given these different semantics, they decided that show() was still useful for Windows, since it did more than setting visibility.

Unfortunately, things are a little more complicated. As a result of this change and the forwarding of new methods throught depreciated methods, this means that setVisible() has now unexpected semantics for Window. If you call setVisible(true) on a window that is already visible, it moves the window to the front.

What bothers me about this is that Window already has a toFront() method and a setVisible() method. There's no need to combine them in a less obvious show() method. Furthermore, invoking setVisible() on a window simply results in a call to Window's show() method anyway. Bottom line: I think this is simply a poor design choice.

Bill Pugh gets a free copy of JavaBeans for his answer just as soon as he sends me his snail mail address. More responses are on the responses page.

From: pugh@cs.umd.edu (Bill Pugh)
Message-Id: <199807012030.QAA03885@aufait.cs.umd.edu>

The semantics of show() for Window are slightly different.
If the Window is already visible, the window is moved to
front. While for components, show() simply made the component
visible.  I'm guessing that given these different semantics,
they decided that show() was still useful for Windows, since it
did more than setting visibility.

Unfortunately, things are a little more complicated. As a result
of this change and the forwarding of new methods throught depreciated
methods, this means that setVisible() has now unexpected
semantics for Window. If you call setVisible(true) on a window
that is already visible, it moves the window to the front.


	Bill Pugh
	pugh@cs.umd.edu
	
From: Charles LeRose <clerose@gr.com>
Subject: Question of the day

> Can anyone explain to me why show() is deprecated
> in java.awt.Component but not in java.awt.Window? 

Due to scheduling pressures, the deprecation tag could not be added
before the API was declared frozen.

Another possibility is that the loss of the show() method in the Window
class would have left less than 4000 methods in that class.  The
embarrassment of allowing such a simple class to exist in the AWT was
simply too much to bear, so they kept show() to flesh it out a bit.

Date: Thu, 02 Jul 1998 10:17:17 -0500
From: Craig Doremus <cdoremus@maine.rr.com>
Subject: Question of the Day

Greetings!

Here's my best answer to your question: Can anyone explain to me why
show() is deprecated in java.awt.Component but not in java.awt.Window?

I believe that the reason that show() in the Window class is still
around because the method both makes the Window instance visible and
brings it to the front (foreground). For other Components, show() is
replaced by setVisible(), which only makes the component visible
(repaints it).

BTW, I think that Cafe au Lait is FANTASTIC! and that your Java Network
Programming book is the best written book on Java -- I recommend it to
every one I know.

-- Craig
-----------------------
Craig Doremus
Programmer
MacImage of Maine
cdoremus@maine.rr.com
207-767-8241
-----------------------

From: "Erwin Moedersheim" <ibm.erwin@novamark.com>
Subject: Q of the day: show()

First answer: The semantics of the two methods are different.
The semantics  of the "show()" method in Window are "If this
window is not yet  visible, make it visible. If this window is
already visible, then bring it to  the front" (JDK1.0.2, and
similar in JDK 1.1.6). Thus, the method  "show()" method in
Window not only renders it visible, it also brings  it to the
front.�  On the other hand, the semantics of the  deprecated
method in Component were "Shows this component; if this 
component had been made invisible by a call to the hide method,
makes this  component visible again." In other words, it only
sets the Component to  visible or not.  Apparently, the powers
at Sun decided to turn  "visible" into a Java Beans property of
Component in JDK 1.1, renaming  "show()" and "show(boolean)" to 
"setVisible(boolean)". However, the "show()" method of  Window
stayed, since it also executes the "toFront()"  action. � 

2) Second answer: You should know better than to question the
authority of the  Java PAS in this matter. Let's have fourty!
(Push-ups or GridBagLayouts, that's  up to you).  � 

Cheers,
Erwin

Date: Wed, 1 Jul 1998 10:33:33 -0400 (EDT)
From: Richard Jefts

Well first off, Sun wanted to make the API more consistent with the
JavaBeans spec, thus creating the setVisible method. For a component,
setVisible does exactly what the deprecated show did. For a window,
however, setVisible and show have two different meanings. setVisible only
makes the window visible, while show makes the window visible and brings
it to the front. In this way, unlike the old show method, setVisible does
the same thing for both components and windows, making the API easier to
understand.

richie

Richard Jefts
babs@hops.cs.jhu.edu

From: David Soroko <davids@mannanetwork.com>
Subject: why show() is deprecated

Here is what I think

Component.show() is deprecated because it does not conform to
the set/get pattern.

The only reason I can think of not making Window.show()
deprecated is that it has some functionality for which there is
no decent alternative access (such as setVisible() is for show()
).

My guess is that this functionality is the generation of the
WINDOW_OPENED event which is fired the first time Window.show()
is invoked.

BTW internally Window.show() invokes the (deprecated)
Component.show()


--
David Soroko
davids@mannanetwork.com
Manna Network Technologies


From: "Marlon Jacobs" <marlon_jacobs@hotmail.com>
To: elharo@ibiblio.org

"show() is depreciated in java.awt.Component but not in java.awt.Window" 
because components have to be arranged first and sorted and then added 
to a layout as if they are not the components would be clump together, 
whereas in windows objects are generally  placed into the centre of a 
window.



[ Cafe au Lait | Books | Trade Shows | Links | FAQ | Tutorial | User Groups ]

Copyright 1998 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified July 2, 1998