Java Component.show() / hide() 已弃用......为什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/636550/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java Component.show() / hide() are deprecated ... why?
提问by user43685
Does anyone know the reason why these Java swing methods are deprecated :
有谁知道不推荐使用这些 Java 摆动方法的原因:
Component.show();
Component.hide();
回答by Michael Myers
Most likely because they don't conform to the standard get/set naming scheme (theysay, "As of JDK version 1.1, replaced by setVisible(boolean)
").
很可能是因为它们不符合标准的 get/set 命名方案(他们说,“从 JDK 1.1 版开始,被替换为setVisible(boolean)
”)。
回答by n00ki3
As of JDK version 1.1, replaced by Component.setVisible(boolean).
从 JDK 1.1 版开始,由 Component.setVisible(boolean) 替换。
回答by mainstringargs
The hide and show methods of java.awt.Component have been deprecated for a while.
java.awt.Component 的 hide 和 show 方法已经弃用了一段时间。
The proper way to set the visibility of a component is setVisible(boolean b)
设置组件可见性的正确方法是 setVisible(boolean b)
回答by TofuBeer
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.
JDK 1.1 引入了 Java Bean。Java Bean 依靠反射和内省来确定 Bean 的属性是什么(Bean 是“组件”)。然后属性显示在属性表中。
By default beans use the following foormat:
默认 bean 使用以下格式:
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.
所以显示/隐藏不符合命名模式,并被替换为 setVisible(boolean) 。
回答by xiaolong
You can use alternative: someUseFrame.setVisible(true);
您可以使用替代方法: someUseFrame.setVisible(true);