java – JComponent.isShowing()和isDisplayable()之间的区别
作者:互联网
Component.isShowing()
和Component.isDisplayable()
有什么区别?我想用它们来决定我应该停止/启动一个Timer.
解决方法:
一个组件
isShowing()何时
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()仅验证组件的状态,而不验证其父组件的状态.
这意味着您的组件当前显示在框架,面板等的屏幕上.
setVisible(true) – > isShowing()返回true(在大多数情况下)
setVisible(false) – > isShowing()返回false(在所有情况下)
isDisplayable()何时
Determines whether this component is displayable. A component is
displayable when it is connected to a native screen resource.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.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.
标签:jcomponent,java,swing 来源: https://codeday.me/bug/20191007/1869533.html