Java Component.show() / hide() are deprecated … why?

前端 未结 5 1403
星月不相逢
星月不相逢 2021-01-17 10:59

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

Component.show(); 
Component.hide();
相关标签:
5条回答
  • 2021-01-17 11:19

    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)").

    0 讨论(0)
  • 2021-01-17 11:24

    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.

    0 讨论(0)
  • 2021-01-17 11:26

    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)

    0 讨论(0)
  • 2021-01-17 11:44

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

    0 讨论(0)
  • 2021-01-17 11:45

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

    0 讨论(0)
提交回复
热议问题