Java Component.show() / hide() are deprecated … wh

2020-04-02 05:58发布

问题:

Does anyone know the reason why these Java swing methods are deprecated :

Component.show(); 
Component.hide();

回答1:

JDK 1.1 introduced Java Beans. Java Beans rely in reflection and introspection to determine what the properties of a Bean are (a Bean is a "component"). Properties are then displayed in a Property Sheet.

By default beans use the following foormat:

boolean isXXX()
<type> getXXX()
void setXXX(<type>)

(going from memory on these next two... they are for indexed properties)

<type> getXXX(int)
void setXXX(<type>, int)

You can override the defaults, but rather than do that most things just rely on the naming pattern.

So show/hide didn't conform to the naming pattern and were replaced with setVisible(boolean) which did.



回答2:

Most likely because they don't conform to the standard get/set naming scheme (they say, "As of JDK version 1.1, replaced by setVisible(boolean)").



回答3:

As of JDK version 1.1, replaced by Component.setVisible(boolean).



回答4:

You can use alternative: someUseFrame.setVisible(true);



回答5:

The hide and show methods of java.awt.Component have been deprecated for a while.

The proper way to set the visibility of a component is setVisible(boolean b)