JComponent.isShowing()和isDisplayable()之间的区别 [英] Difference between JComponent.isShowing() and isDisplayable()
问题描述
Component.isShowing()
和 Component.isDisplayable()
?我想用它们来决定我应该停止/启动一个Timer。
What's the difference between Component.isShowing()
and Component.isDisplayable()
? I want to use them to decide wheter I should stop/start a Timer.
推荐答案
一个组件
isShowing()
when
确定此组件是否在屏幕上显示。这意味着
组件必须是可见的,并且它必须位于
可见并显示的容器中。
Determines whether this component is showing on screen. This means that the component must be visible, and it must be in a container that is visible and showing.
isShowing()
是递归的并检查所有父组件,但是 isDisplayable()
和 isVisible()
仅验证组件的状态,而不验证其父级的状态。
isShowing()
is recursive and checks all parent components, too, but isDisplayable()
and isVisible()
verify only the state of the component, not that state of its parents.
这意味着您的组件当前显示在框架,面板等屏幕上。
setVisible(true)
- > isShowing()
返回true(大多数情况下)
setVisible(false)
- > isShowing()
返回false(在所有情况下)
This means that your component is currently showing on the screen within a Frame, Panel, etc.
setVisible(true)
--> isShowing()
returns true (in most cases)
setVisible(false)
--> isShowing()
returns false (in all cases)
isDisplayable()
when
确定此组件是否可显示。当组件连接到本机屏幕资源时,该组件可以显示
。
Determines whether this component is displayable. A component is displayable when it is connected to a native screen resource.
当一个组件被添加到可显示的
包含层次结构中或者当其包含层次结构为
displayable时,该组件可显示。当
祖先窗口打包或可见时,可以显示包含层次结构。
A component is made displayable either when it is added to a displayable containment hierarchy or when its containment hierarchy is made displayable. A containment hierarchy is made displayable when its ancestor window is either packed or made visible.
组件从$ b中删除时不可显示$ b可显示的包含层次结构或当其包含层次结构为
时不可显示。当
其祖先窗口被释放时,包含层次结构将无法显示。
A component is made undisplayable either when it is removed from a displayable containment hierarchy or when its containment hierarchy is made undisplayable. A containment hierarchy is made undisplayable when its ancestor window is disposed.
这意味着您的组件处于以下状态:它可以显示在屏幕上,但不需要当前显示在屏幕上,以显示可显示的
状态。例如,即使之前在组件上调用 setVisible(false)
(因此组件不可见)组件仍然是可显示
和 isDisplayable()
将返回true。
This means that your component is in a state where it can be shown on the screen but it doesn't need to be currently shown on the screen to be in a displayable
state. E.g., even if setVisible(false)
was called on the component before (so the component is "invisible") the component is still displayable
and isDisplayable()
will return true.
这篇关于JComponent.isShowing()和isDisplayable()之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!